Skip to content
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

🐛 add enable-sync-labels flag to klusterlet operator #505

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/cmd/spoke/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func NewKlusterletOperatorCmd() *cobra.Command {
flags.BoolVar(&klOptions.DisableAddonNamespace, "disable-default-addon-namespace", false,
"If set, will not create default open-cluster-management-agent-addon ns")

flags.BoolVar(&klOptions.EnableSyncLabels, "enable-sync-labels", false,
"If set, will sync the labels of Klusterlet CR to all agent resources")

opts.AddFlags(flags)

return cmd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ func TestSyncDelete(t *testing.T) {
newAppliedManifestWorks("testhost-2", []string{workv1.AppliedManifestWorkFinalizer}, false),
}
syncContext := testingcommon.NewFakeSyncContext(t, "klusterlet")
controller := newTestController(t, klusterlet, syncContext.Recorder(), appliedManifestWorks, namespace, bootstrapKubeConfigSecret)
controller := newTestController(t, klusterlet, syncContext.Recorder(), appliedManifestWorks, false,
namespace, bootstrapKubeConfigSecret)

err := controller.cleanupController.sync(context.TODO(), syncContext)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type klusterletController struct {
controlPlaneNodeLabelSelector string
deploymentReplicas int32
disableAddonNamespace bool
enableSyncLabels bool
}

type klusterletReconcile interface {
Expand Down Expand Up @@ -83,6 +84,7 @@ func NewKlusterletController(
controlPlaneNodeLabelSelector string,
deploymentReplicas int32,
disableAddonNamespace bool,
enableSyncLabels bool,
recorder events.Recorder) factory.Controller {
controller := &klusterletController{
kubeClient: kubeClient,
Expand All @@ -96,6 +98,7 @@ func NewKlusterletController(
controlPlaneNodeLabelSelector: controlPlaneNodeLabelSelector,
deploymentReplicas: deploymentReplicas,
disableAddonNamespace: disableAddonNamespace,
enableSyncLabels: enableSyncLabels,
}

return factory.New().WithSync(controller.sync).
Expand Down Expand Up @@ -225,7 +228,10 @@ func (n *klusterletController) sync(ctx context.Context, controllerContext facto
ResourceRequirementResourceType: helpers.ResourceType(klusterlet),
ResourceRequirements: resourceRequirements,
DisableAddonNamespace: n.disableAddonNamespace,
Labels: helpers.GetKlusterletAgentLabels(klusterlet),
}

if n.enableSyncLabels {
config.Labels = helpers.GetKlusterletAgentLabels(klusterlet)
}

managedClusterClients, err := n.managedClusterClientsBuilder.
Expand Down
Loading
Loading