-
Notifications
You must be signed in to change notification settings - Fork 124
feat(apiserver): implement APIService caBundle reconciliation #1808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
praveenrewar
merged 5 commits into
carvel-dev:develop
from
himsngh:add-certs-reconcilation
Apr 6, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1ba5f19
feat(apiserver): implement APIService caBundle reconciliation
himsngh 60bfee9
chore: resolve review comments
himsngh b843c87
chore: add vendor modules.txt changes
himsngh b4c4858
update golangci-lint version to 2.11
himsngh baecdc3
go mod vendor changes
himsngh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,5 +28,5 @@ jobs: | |
| - name: golangci-lint | ||
| uses: golangci/golangci-lint-action@v7 | ||
| with: | ||
| version: v2.4 | ||
| version: v2.11 | ||
| args: -v | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // Copyright 2026 The Carvel Authors. | ||
|
praveenrewar marked this conversation as resolved.
|
||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package apiserver | ||
|
himsngh marked this conversation as resolved.
|
||
|
|
||
| import ( | ||
| "context" | ||
| "crypto/x509" | ||
| "testing" | ||
|
|
||
| "github.com/go-logr/logr" | ||
| "github.com/stretchr/testify/require" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apiserver/pkg/server/dynamiccertificates" | ||
| clienttesting "k8s.io/client-go/testing" | ||
| apiregv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" | ||
| fakeaggregator "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/fake" | ||
| ) | ||
|
|
||
| // fakeCAProvider implements dynamiccertificates.CAContentProvider | ||
| type fakeCAProvider struct { | ||
| bundle []byte | ||
| } | ||
|
|
||
| func (f *fakeCAProvider) Name() string { return "fake-ca-provider" } | ||
| func (f *fakeCAProvider) CurrentCABundleContent() []byte { return f.bundle } | ||
| func (f *fakeCAProvider) AddListener(_ dynamiccertificates.Listener) {} | ||
| func (f *fakeCAProvider) VerifyOptions() (x509.VerifyOptions, bool) { | ||
| return x509.VerifyOptions{}, false | ||
| } | ||
|
|
||
| func Test_updateAPIService(t *testing.T) { | ||
| logger := logr.Discard() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| existingBundle []byte | ||
| newBundle []byte | ||
| expectUpdate bool | ||
| }{ | ||
| { | ||
| name: "updates APIService when CA bundle is different", | ||
| existingBundle: []byte("old-dead-pod-cert"), | ||
| newBundle: []byte("new-active-pod-cert"), | ||
| expectUpdate: true, | ||
| }, | ||
| { | ||
| name: "does nothing when CA bundle is identical", | ||
| existingBundle: []byte("active-pod-cert"), | ||
| newBundle: []byte("active-pod-cert"), | ||
| expectUpdate: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| apiSvc := &apiregv1.APIService{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: apiServiceName}, | ||
| Spec: apiregv1.APIServiceSpec{ | ||
| CABundle: tc.existingBundle, | ||
| }, | ||
| } | ||
| fakeClient := fakeaggregator.NewSimpleClientset(apiSvc) | ||
|
|
||
| fakeProvider := &fakeCAProvider{bundle: tc.newBundle} | ||
|
|
||
| err := updateAPIService(context.TODO(), logger, fakeClient, fakeProvider) | ||
| require.NoError(t, err) | ||
|
|
||
| actions := fakeClient.Actions() | ||
| require.GreaterOrEqual(t, len(actions), 1, "expected at least a GET action") | ||
| require.Equal(t, "get", actions[0].GetVerb()) | ||
|
|
||
| var updateActionFound bool | ||
| for _, action := range actions { | ||
| if action.GetVerb() == "update" { | ||
| updateActionFound = true | ||
| updateAction, ok := action.(clienttesting.UpdateAction) | ||
| if !ok { | ||
| t.Fatalf("Expected UpdateAction, got %T", action) | ||
| } | ||
| updatedSvc := updateAction.GetObject().(*apiregv1.APIService) | ||
| require.Equal(t, tc.newBundle, updatedSvc.Spec.CABundle) | ||
| } | ||
| } | ||
|
|
||
| if tc.expectUpdate { | ||
| require.True(t, updateActionFound, "expected an UPDATE action to be executed, but none was found") | ||
| } else { | ||
| require.False(t, updateActionFound, "expected NO UPDATE action, but one was executed") | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
himsngh marked this conversation as resolved.
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.