Skip to content

Commit

Permalink
Update api dependency and remove unnecessary featureGate enabling part
Browse files Browse the repository at this point in the history
Signed-off-by: Rokibul Hasan <[email protected]>
  • Loading branch information
RokibulHasan7 committed Nov 6, 2024
1 parent 2b86b8d commit b29c2e9
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
k8s.io/kube-aggregator v0.30.3
k8s.io/utils v0.0.0-20240310230437-4693a0247e57
open-cluster-management.io/addon-framework v0.11.0
open-cluster-management.io/api v0.15.0
open-cluster-management.io/api v0.15.1-0.20241106012558-db876bf4ff8a
open-cluster-management.io/sdk-go v0.15.0
sigs.k8s.io/cluster-inventory-api v0.0.0-20240730014211-ef0154379848
sigs.k8s.io/controller-runtime v0.18.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ k8s.io/utils v0.0.0-20240310230437-4693a0247e57 h1:gbqbevonBh57eILzModw6mrkbwM0g
k8s.io/utils v0.0.0-20240310230437-4693a0247e57/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
open-cluster-management.io/addon-framework v0.11.0 h1:ZJxphgHQ36VUJF0RIag+nzcEn5PNyep2rsEPdz6wT7o=
open-cluster-management.io/addon-framework v0.11.0/go.mod h1:ruMU8i/dciz3qCv2CQ46Cu1b7rkK7TpvB+W4bRwHf+I=
open-cluster-management.io/api v0.15.0 h1:lRee1KOlGHZb2scTA7ff9E9Fxt2hJc7jpkHnaCbvkOU=
open-cluster-management.io/api v0.15.0/go.mod h1:9erZEWEn4bEqh0nIX2wA7f/s3KCuFycQdBrPrRzi0QM=
open-cluster-management.io/api v0.15.1-0.20241106012558-db876bf4ff8a h1:QTljOjTR8jDpw/EWhOoakGcStGVftQkBWHVxGZMhEUQ=
open-cluster-management.io/api v0.15.1-0.20241106012558-db876bf4ff8a/go.mod h1:9erZEWEn4bEqh0nIX2wA7f/s3KCuFycQdBrPrRzi0QM=
open-cluster-management.io/sdk-go v0.15.0 h1:2IAJnPfUoY6rPC5w7LhqAnvIlgekPoVW03LdZO1unIM=
open-cluster-management.io/sdk-go v0.15.0/go.mod h1:fi5WBsbC5K3txKb8eRLuP0Sim/Oqz/PHX18skAEyjiA=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.29.0 h1:/U5vjBbQn3RChhv7P11uhYvCSm5G2GaIi5AIGBS6r4c=
Expand Down
26 changes: 15 additions & 11 deletions pkg/operator/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
apiregistrationclient "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/typed/apiregistration/v1"

"open-cluster-management.io/api/feature"
operatorapiv1 "open-cluster-management.io/api/operator/v1"
)

Expand Down Expand Up @@ -72,13 +71,6 @@ var (
genericScheme = runtime.NewScheme()
genericCodecs = serializer.NewCodecFactory(genericScheme)
genericCodec = genericCodecs.UniversalDeserializer()

DefaultHubRegistrationFeatureGates = []operatorapiv1.FeatureGate{
{Feature: string(feature.DefaultClusterSet), Mode: operatorapiv1.FeatureGateModeTypeEnable},
}
DefaultSpokeRegistrationFeatureGates = []operatorapiv1.FeatureGate{
{Feature: string(feature.AddonManagement), Mode: operatorapiv1.FeatureGateModeTypeEnable},
}
)

func init() {
Expand Down Expand Up @@ -775,11 +767,23 @@ func ConvertToFeatureGateFlags(component string, features []operatorapiv1.Featur
continue
}

if feature.Mode == operatorapiv1.FeatureGateModeTypeDisable && defaultFeature.Default {
if feature.Mode == operatorapiv1.FeatureGateModeTypeEnable {
flags = append(flags, fmt.Sprintf("--feature-gates=%s=true", feature.Feature))
} else if feature.Mode == operatorapiv1.FeatureGateModeTypeDisable && defaultFeature.Default {
flags = append(flags, fmt.Sprintf("--feature-gates=%s=false", feature.Feature))
}
if feature.Mode == operatorapiv1.FeatureGateModeTypeEnable && !defaultFeature.Default {
flags = append(flags, fmt.Sprintf("--feature-gates=%s=true", feature.Feature))
}

// Create a map for quick lookup of features arrays items
featureMap := make(map[string]bool)
for _, feature := range features {
featureMap[feature.Feature] = true
}

// enable default feature gates
for feature, spec := range defaultFeatureGates {
if _, ok := featureMap[string(feature)]; !ok && spec.Default {
flags = append(flags, fmt.Sprintf("--feature-gates=%s=true", feature))
}
}

Expand Down
11 changes: 7 additions & 4 deletions pkg/operator/helpers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"reflect"
"sort"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -1572,15 +1573,15 @@ func TestConvertToFeatureGateFlags(t *testing.T) {
{
name: "unset",
features: []operatorapiv1.FeatureGate{},
desiredFlags: []string{},
desiredFlags: []string{"--feature-gates=ClusterClaim=true", "--feature-gates=AddonManagement=true"},
},
{
name: "enable feature",
features: []operatorapiv1.FeatureGate{
{Feature: "ClusterClaim", Mode: operatorapiv1.FeatureGateModeTypeEnable},
{Feature: "AddonManagement", Mode: operatorapiv1.FeatureGateModeTypeEnable},
},
desiredFlags: []string{},
desiredFlags: []string{"--feature-gates=ClusterClaim=true", "--feature-gates=AddonManagement=true"},
},
{
name: "disable feature",
Expand All @@ -1596,7 +1597,7 @@ func TestConvertToFeatureGateFlags(t *testing.T) {
{Feature: "Foo", Mode: operatorapiv1.FeatureGateModeTypeDisable},
{Feature: "Bar", Mode: operatorapiv1.FeatureGateModeTypeDisable},
},
desiredFlags: []string{},
desiredFlags: []string{"--feature-gates=ClusterClaim=true", "--feature-gates=AddonManagement=true"},
desiredMsg: "test: [Foo Bar]",
},
}
Expand All @@ -1607,7 +1608,9 @@ func TestConvertToFeatureGateFlags(t *testing.T) {
if msg != tc.desiredMsg {
t.Errorf("Name: %s, unexpected message, got: %s, desired %s", tc.name, msg, tc.desiredMsg)
}
if !equality.Semantic.DeepEqual(flags, tc.desiredFlags) {
sort.Strings(flags)
sort.Strings(tc.desiredFlags)
if !reflect.DeepEqual(flags, tc.desiredFlags) {
t.Errorf("Name: %s, unexpected flags, got %v, desired %v", tc.name, flags, tc.desiredFlags)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (n *clusterManagerController) sync(ctx context.Context, controllerContext f
var registrationFeatureMsgs, workFeatureMsgs, addonFeatureMsgs string
// If there are some invalid feature gates of registration or work, will output
// condition `ValidFeatureGates` False in ClusterManager.
registrationFeatureGates := helpers.DefaultHubRegistrationFeatureGates
var registrationFeatureGates []operatorapiv1.FeatureGate
if clusterManager.Spec.RegistrationConfiguration != nil {
registrationFeatureGates = clusterManager.Spec.RegistrationConfiguration.FeatureGates
config.AutoApproveUsers = strings.Join(clusterManager.Spec.RegistrationConfiguration.AutoApproveUsers, ",")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (n *klusterletController) sync(ctx context.Context, controllerContext facto
// function is enabled, additional permissions for get, list, and watch RBAC resources required by this
// function need to be applied
var registrationFeatureMsgs, workFeatureMsgs string
registrationFeatureGates := helpers.DefaultSpokeRegistrationFeatureGates
var registrationFeatureGates []operatorapiv1.FeatureGate
if klusterlet.Spec.RegistrationConfiguration != nil {
registrationFeatureGates = klusterlet.Spec.RegistrationConfiguration.FeatureGates
config.ClientCertExpirationSeconds = klusterlet.Spec.RegistrationConfiguration.ClientCertExpirationSeconds
Expand Down
4 changes: 0 additions & 4 deletions pkg/registration/hub/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ var _ = ginkgo.BeforeSuite(func() {
err = clusterv1.Install(scheme.Scheme)
gomega.Expect(err).NotTo(gomega.HaveOccurred())

// enable DefaultClusterSet feature gate
err = features.HubMutableFeatureGate.Set("DefaultClusterSet=true")
gomega.Expect(err).ToNot(gomega.HaveOccurred())

// enable ManagedClusterAutoApproval feature gate
err = features.HubMutableFeatureGate.Set("ManagedClusterAutoApproval=true")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
Expand Down
3 changes: 0 additions & 3 deletions pkg/registration/webhook/v1/managedcluster_mutating_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,6 @@ func TestDefault(t *testing.T) {
},
}
runtime.Must(features.HubMutableFeatureGate.Add(ocmfeature.DefaultHubRegistrationFeatureGates))
if err := features.HubMutableFeatureGate.Set(fmt.Sprintf("%s=true", string(ocmfeature.DefaultClusterSet))); err != nil {
t.Fatal(err)
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
w := ManagedClusterWebhook{}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/operator/klusterlet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ var _ = ginkgo.Describe("Klusterlet", func() {
return false
}
gomega.Expect(len(actual.Spec.Template.Spec.Containers)).Should(gomega.Equal(1))
gomega.Expect(len(actual.Spec.Template.Spec.Containers[0].Args)).Should(gomega.Equal(6))
gomega.Expect(len(actual.Spec.Template.Spec.Containers[0].Args)).Should(gomega.Equal(8))
return actual.Spec.Template.Spec.Containers[0].Args[2] == "--spoke-cluster-name=cluster2"
}, eventuallyTimeout, eventuallyInterval).Should(gomega.BeTrue())

Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ open-cluster-management.io/addon-framework/pkg/agent
open-cluster-management.io/addon-framework/pkg/assets
open-cluster-management.io/addon-framework/pkg/index
open-cluster-management.io/addon-framework/pkg/utils
# open-cluster-management.io/api v0.15.0
# open-cluster-management.io/api v0.15.1-0.20241106012558-db876bf4ff8a
## explicit; go 1.22.0
open-cluster-management.io/api/addon/v1alpha1
open-cluster-management.io/api/client/addon/clientset/versioned
Expand Down
2 changes: 1 addition & 1 deletion vendor/open-cluster-management.io/api/feature/feature.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b29c2e9

Please sign in to comment.