Skip to content

Commit b0066c9

Browse files
committed
Merge branch 'main' of https://github.com/kubefleet-dev/kubefleet into feat/status-backreporting-controller
2 parents df26f8b + 6511b20 commit b0066c9

File tree

136 files changed

+14506
-1757
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+14506
-1757
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Implementation: Kubernetes Version Collection with TTL Caching
2+
3+
## Overview
4+
Add a `collectK8sVersion` function to the Azure property provider that collects the Kubernetes server version using the discoveryClient with a 15-minute TTL cache to minimize API calls.
5+
6+
## Plan
7+
8+
### Phase 1: Add Cache Fields
9+
**Task 1.1: Add cache-related fields to PropertyProvider struct**
10+
- Add `cachedK8sVersion` string field to store the cached version
11+
- Add `k8sVersionCacheTime` time.Time field to track when the cache was last updated
12+
- Add `k8sVersionCacheTTL` time.Duration field set to 15 minutes
13+
- Add a mutex for thread-safe access to cached values
14+
15+
### Phase 2: Implement collectK8sVersion Function
16+
**Task 2.1: Implement the collectK8sVersion function**
17+
- Check if cached version exists and is still valid (within TTL)
18+
- If cache is valid, return cached version
19+
- If cache is expired or empty, call discoveryClient.ServerVersion()
20+
- Update cache with new version and current timestamp
21+
- Return the version as a property with observation time
22+
23+
### Phase 3: Integrate into Collect Method
24+
**Task 3.1: Call collectK8sVersion in Collect method**
25+
- Add call to collectK8sVersion in the Collect method
26+
- Store the k8s version in the properties map
27+
28+
### Phase 4: Write Unit Tests
29+
**Task 4.1: Create unit tests for collectK8sVersion**
30+
- Test cache hit scenario (cached version within TTL)
31+
- Test cache miss scenario (no cached version)
32+
- Test cache expiration scenario (cached version expired)
33+
- Test error handling from discoveryClient
34+
- Test thread safety of cache access
35+
36+
### Phase 5: Verify Tests Pass
37+
**Task 5.1: Run unit tests**
38+
- Execute `go test` for the provider package
39+
- Verify all tests pass
40+
41+
## Success Criteria
42+
- [x] Cache fields added to PropertyProvider struct
43+
- [x] collectK8sVersion function implemented with TTL logic
44+
- [x] Function integrated into Collect method
45+
- [x] Unit tests created and passing
46+
- [x] Thread-safe implementation verified
47+
48+
## Implementation Notes
49+
- Using sync.RWMutex for thread-safe cache access
50+
- TTL set to 15 minutes as specified
51+
- Uses the standard `propertyprovider.K8sVersionProperty` constant instead of creating a new one
52+
- Changed `discoveryClient` field type from `discovery.DiscoveryInterface` to `discovery.ServerVersionInterface` for better testability and to only depend on the interface we actually need
53+
- Fixed test nil pointer issue by conditionally setting the discoveryClient field only when it's non-nil
54+
55+
## Final Implementation Summary
56+
All tasks completed successfully. The `collectK8sVersion` function now:
57+
1. Caches the Kubernetes version with a 15-minute TTL
58+
2. Uses thread-safe mutex locks for concurrent access
59+
3. Properly handles nil discovery client cases
60+
4. Returns early if cache is still valid to minimize API calls
61+
5. Updates cache atomically when fetching new version
62+
6. Has comprehensive unit tests covering all scenarios including cache hits, misses, expiration, errors, and concurrency
63+
64+
## Integration Test Updates
65+
Updated integration tests to ignore the new k8s version property in comparisons:
66+
- Added `ignoreK8sVersionProperty` using `cmpopts.IgnoreMapEntries` to filter out the k8s version from test expectations
67+
- Integration tests now pass successfully (33 specs all passed)
68+
- The k8s version is being collected correctly from the test Kubernetes environment, validating the implementation works end-to-end
69+
70+
## Test Results
71+
- Unit tests: ✅ 8/8 passed (7 in TestCollectK8sVersion + 1 in TestCollectK8sVersionConcurrency)
72+
- Integration tests: ✅ 33/33 specs passed
73+
- All scenarios validated including cache behavior, TTL expiration, error handling, and thread safety
74+
75+
## Refactoring
76+
Simplified the implementation by removing the `k8sVersionCacheTTL` instance field from PropertyProvider:
77+
- Removed the `k8sVersionCacheTTL time.Duration` field from the struct
78+
- Updated `collectK8sVersion` to use the `K8sVersionCacheTTL` constant directly
79+
- Removed field initialization from `New()` and `NewWithPricingProvider()` constructors
80+
- Updated unit tests to remove the field from test PropertyProvider instances
81+
- All tests still pass after refactoring ✅

.github/workflows/chart.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
deploy:
1919
runs-on: ubuntu-latest
2020
steps:
21-
- uses: actions/checkout@v5
21+
- uses: actions/checkout@v6.0.1
2222
with:
2323
submodules: true
2424
fetch-depth: 0

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
go-version: ${{ env.GO_VERSION }}
4141

4242
- name: Check out code into the Go module directory
43-
uses: actions/checkout@v5
43+
uses: actions/checkout@v6.0.1
4444

4545
- name: Set up Ginkgo CLI
4646
run: |
@@ -91,7 +91,7 @@ jobs:
9191
go-version: ${{ env.GO_VERSION }}
9292

9393
- name: Check out code into the Go module directory
94-
uses: actions/checkout@v5
94+
uses: actions/checkout@v6.0.1
9595

9696
- name: Install Ginkgo CLI
9797
run: |
@@ -139,7 +139,7 @@ jobs:
139139

140140
- name: Upload logs
141141
if: always()
142-
uses: actions/upload-artifact@v5
142+
uses: actions/upload-artifact@v6
143143
with:
144144
name: e2e-logs-${{ matrix.customized-settings }}
145145
path: test/e2e/logs-${{ matrix.customized-settings }}/

.github/workflows/code-lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
go-version: ${{ env.GO_VERSION }}
4444

4545
- name: Checkout
46-
uses: actions/checkout@v5
46+
uses: actions/checkout@v6.0.1
4747
with:
4848
submodules: true
4949

@@ -64,7 +64,7 @@ jobs:
6464
go-version: ${{ env.GO_VERSION }}
6565

6666
- name: Check out code into the Go module directory
67-
uses: actions/checkout@v5
67+
uses: actions/checkout@v6.0.1
6868

6969
- name: golangci-lint
7070
run: make lint

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838

3939
steps:
4040
- name: Checkout repository
41-
uses: actions/checkout@v5
41+
uses: actions/checkout@v6.0.1
4242

4343
# Initializes the CodeQL tools for scanning.
4444
- name: Initialize CodeQL

.github/workflows/codespell.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Harden Runner
15-
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
15+
uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
1616
with:
1717
egress-policy: audit
1818

19-
- uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493 # v4.1.7
20-
- uses: codespell-project/actions-codespell@406322ec52dd7b488e48c1c4b82e2a8b3a1bf630 # master
19+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v4.1.7
20+
- uses: codespell-project/actions-codespell@8f01853be192eb0f849a5c7d721450e7a467c579 # master
2121
with:
2222
check_filenames: true
2323
skip: ./.git,./.github/workflows/codespell.yml,.git,*.png,*.jpg,*.svg,*.sum,./vendor,go.sum,testdata

.github/workflows/markdown-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
markdown-link-check:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v5
13+
- uses: actions/checkout@v6.0.1
1414
- uses: tcort/github-action-markdown-link-check@v1
1515
with:
1616
# this will only show errors in the output

.github/workflows/release.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Release Images
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
workflow_dispatch:
8+
inputs:
9+
tag:
10+
description: 'Release tag (e.g., v1.0.0)'
11+
required: true
12+
type: string
13+
14+
permissions:
15+
contents: read
16+
packages: write
17+
18+
env:
19+
REGISTRY: ghcr.io
20+
HUB_AGENT_IMAGE_NAME: hub-agent
21+
MEMBER_AGENT_IMAGE_NAME: member-agent
22+
REFRESH_TOKEN_IMAGE_NAME: refresh-token
23+
GO_VERSION: '1.24.9'
24+
25+
jobs:
26+
export-registry:
27+
runs-on: ubuntu-latest
28+
outputs:
29+
registry: ${{ steps.export.outputs.registry }}
30+
tag: ${{ steps.export.outputs.tag }}
31+
steps:
32+
- name: Checkout code
33+
uses: actions/[email protected]
34+
35+
- id: export
36+
run: |
37+
# registry must be in lowercase
38+
echo "registry=$(echo "${{ env.REGISTRY }}/${{ github.repository }}" | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
39+
40+
# Extract tag from github ref or workflow input
41+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
42+
TAG="${{ inputs.tag }}"
43+
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
44+
TAG=${GITHUB_REF#refs/tags/}
45+
else
46+
echo "Error: Workflow triggered by unsupported event or ref"
47+
echo "Event: ${{ github.event_name }}"
48+
echo "Ref: ${{ github.ref }}"
49+
exit 1
50+
fi
51+
echo "tag=${TAG}" >> $GITHUB_OUTPUT
52+
echo "Release tag: ${TAG}"
53+
54+
build-and-publish:
55+
needs: export-registry
56+
env:
57+
REGISTRY: ${{ needs.export-registry.outputs.registry }}
58+
TAG: ${{ needs.export-registry.outputs.tag }}
59+
runs-on: ubuntu-latest
60+
steps:
61+
- name: Set up Go ${{ env.GO_VERSION }}
62+
uses: actions/setup-go@v6
63+
with:
64+
go-version: ${{ env.GO_VERSION }}
65+
66+
- name: Checkout code
67+
uses: actions/[email protected]
68+
69+
- name: Login to ghcr.io
70+
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef
71+
with:
72+
registry: ghcr.io
73+
username: ${{ github.actor }}
74+
password: ${{ secrets.GITHUB_TOKEN }}
75+
76+
- name: Build and push images with tag ${{ env.TAG }}
77+
run: |
78+
make push
79+
80+
- name: Verify images
81+
run: |
82+
echo "✅ Published images:"
83+
echo " - ${{ env.REGISTRY }}/${{ env.HUB_AGENT_IMAGE_NAME }}:${{ env.TAG }}"
84+
echo " - ${{ env.REGISTRY }}/${{ env.MEMBER_AGENT_IMAGE_NAME }}:${{ env.TAG }}"
85+
echo " - ${{ env.REGISTRY }}/${{ env.REFRESH_TOKEN_IMAGE_NAME }}:${{ env.TAG }}"
86+
echo ""
87+
echo "📦 Images are now public!"

.github/workflows/trivy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
go-version: ${{ env.GO_VERSION }}
4545

4646
- name: Checkout code
47-
uses: actions/checkout@v5
47+
uses: actions/checkout@v6.0.1
4848

4949
- name: Login to ${{ env.REGISTRY }}
5050
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef

.github/workflows/upgrade.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
go-version: ${{ env.GO_VERSION }}
4545

4646
- name: Check out code into the Go module directory
47-
uses: actions/checkout@v5
47+
uses: actions/checkout@v6.0.1
4848
with:
4949
# Fetch the history of all branches and tags.
5050
# This is needed for the test suite to switch between releases.
@@ -127,7 +127,7 @@ jobs:
127127
go-version: ${{ env.GO_VERSION }}
128128

129129
- name: Check out code into the Go module directory
130-
uses: actions/checkout@v5
130+
uses: actions/checkout@v6.0.1
131131
with:
132132
# Fetch the history of all branches and tags.
133133
# This is needed for the test suite to switch between releases.
@@ -210,7 +210,7 @@ jobs:
210210
go-version: ${{ env.GO_VERSION }}
211211

212212
- name: Check out code into the Go module directory
213-
uses: actions/checkout@v5
213+
uses: actions/checkout@v6.0.1
214214
with:
215215
# Fetch the history of all branches and tags.
216216
# This is needed for the test suite to switch between releases.

0 commit comments

Comments
 (0)