-
Notifications
You must be signed in to change notification settings - Fork 160
Default new installs to v3 CRD mode when the cluster supports it #4973
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
caseydavenport
merged 7 commits into
tigera:master
from
caseydavenport:casey-v3-crd-default
Jul 23, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
885e068
Add decideV3CRDs decision for greenfield v3 default
caseydavenport 9f5057c
Detect MutatingAdmissionPolicy availability for greenfield gate
caseydavenport dff0716
Default greenfield installs to v3 CRDs when MutatingAdmissionPolicy i…
caseydavenport 15de260
Assert greenfield v3 render shape for OSS and enterprise
caseydavenport 0503267
Sync enterprise protect-builtin-tiers policy from calico-private
caseydavenport d91c1d0
Refuse to start in v3 CRD mode without MutatingAdmissionPolicy support
caseydavenport f5cd3d8
Inject discovery and dynamic clients into v3 CRD detection
caseydavenport 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
Some comments aren't visible on the classic Files Changed page.
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
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,121 @@ | ||
| // Copyright (c) 2026 Tigera, Inc. All rights reserved. | ||
|
|
||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package apis | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/apimachinery/pkg/runtime/schema" | ||
| dynamicfake "k8s.io/client-go/dynamic/fake" | ||
| "k8s.io/client-go/kubernetes/fake" | ||
| ) | ||
|
|
||
| func mapResourceList() *metav1.APIResourceList { | ||
| return &metav1.APIResourceList{ | ||
| GroupVersion: "admissionregistration.k8s.io/v1beta1", | ||
| APIResources: []metav1.APIResource{{Name: "mutatingadmissionpolicies", Kind: "MutatingAdmissionPolicy"}}, | ||
| } | ||
| } | ||
|
|
||
| // emptyDynamicClient returns a dynamic fake with no DatastoreMigration CRs, so the migration check | ||
| // finds nothing and useV3CRDs falls through to API discovery. | ||
| func emptyDynamicClient() *dynamicfake.FakeDynamicClient { | ||
| return dynamicfake.NewSimpleDynamicClientWithCustomListKinds( | ||
| runtime.NewScheme(), | ||
| map[schema.GroupVersionResource]string{datastoreMigrationGVR: "DatastoreMigrationList"}, | ||
| ) | ||
| } | ||
|
|
||
| func TestUseV3CRDs(t *testing.T) { | ||
| v1 := &metav1.APIResourceList{GroupVersion: "crd.projectcalico.org/v1"} | ||
| v3 := &metav1.APIResourceList{GroupVersion: "projectcalico.org/v3"} | ||
|
|
||
| cases := []struct { | ||
| name string | ||
| apiGroup string | ||
| resources []*metav1.APIResourceList | ||
| want bool | ||
| wantErr bool | ||
| }{ | ||
| {"v1 present stays v1", "", []*metav1.APIResourceList{v1, mapResourceList()}, false, false}, | ||
| {"both present stays v1", "", []*metav1.APIResourceList{v1, v3, mapResourceList()}, false, false}, | ||
| {"v3 present with MAP stays v3", "", []*metav1.APIResourceList{v3, mapResourceList()}, true, false}, | ||
| {"v3 present without MAP errors", "", []*metav1.APIResourceList{v3}, false, true}, | ||
| {"greenfield capable goes v3", "", []*metav1.APIResourceList{mapResourceList()}, true, false}, | ||
| {"greenfield not capable stays v1", "", []*metav1.APIResourceList{}, false, false}, | ||
|
|
||
| {"override v3 with MAP goes v3", "projectcalico.org/v3", []*metav1.APIResourceList{mapResourceList()}, true, false}, | ||
| {"override v3 without MAP errors", "projectcalico.org/v3", []*metav1.APIResourceList{}, false, true}, | ||
| {"override v1 ignores MAP", "crd.projectcalico.org/v1", []*metav1.APIResourceList{}, false, false}, | ||
| } | ||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| if tc.apiGroup != "" { | ||
| t.Setenv("CALICO_API_GROUP", tc.apiGroup) | ||
| } | ||
| c := fake.NewClientset() | ||
| c.Resources = tc.resources | ||
| got, err := useV3CRDs(c.Discovery(), emptyDynamicClient()) | ||
| if (err != nil) != tc.wantErr { | ||
| t.Fatalf("useV3CRDs() err = %v, wantErr %t", err, tc.wantErr) | ||
| } | ||
| if got != tc.want { | ||
| t.Errorf("useV3CRDs() = %t, want %t", got, tc.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestIsMutatingAdmissionPolicyServed(t *testing.T) { | ||
| cases := []struct { | ||
| name string | ||
| resources []*metav1.APIResourceList | ||
| want bool | ||
| }{ | ||
| { | ||
| name: "served when MAP resource present", | ||
| resources: []*metav1.APIResourceList{{ | ||
| GroupVersion: "admissionregistration.k8s.io/v1beta1", | ||
| APIResources: []metav1.APIResource{{Name: "mutatingadmissionpolicies", Kind: "MutatingAdmissionPolicy"}}, | ||
| }}, | ||
| want: true, | ||
| }, | ||
| { | ||
| name: "not served when group present without MAP kind", | ||
| resources: []*metav1.APIResourceList{{ | ||
| GroupVersion: "admissionregistration.k8s.io/v1", | ||
| APIResources: []metav1.APIResource{{Name: "validatingwebhookconfigurations", Kind: "ValidatingWebhookConfiguration"}}, | ||
| }}, | ||
| want: false, | ||
| }, | ||
| { | ||
| name: "not served on empty cluster", | ||
| resources: []*metav1.APIResourceList{}, | ||
| want: false, | ||
| }, | ||
| } | ||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| c := fake.NewClientset() | ||
| c.Resources = tc.resources | ||
| got := isMutatingAdmissionPolicyServed(c.Discovery()) | ||
| if got != tc.want { | ||
| t.Errorf("isMutatingAdmissionPolicyServed() = %t, want %t", got, tc.want) | ||
| } | ||
| }) | ||
| } | ||
| } |
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
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.