Skip to content

Commit

Permalink
Pass spoke cluster name to the agent (#12)
Browse files Browse the repository at this point in the history
Signed-off-by: Rokibul Hasan <[email protected]>
  • Loading branch information
RokibulHasan7 authored Jun 5, 2024
1 parent f4b54f7 commit 26db7e4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
16 changes: 5 additions & 11 deletions pkg/cmds/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func NewCmdAgent() *cobra.Command {
var enableLeaderElection bool
var probeAddr string
var hubKC string
var spokeClusterName string
opts := zap.Options{
Development: true,
}
Expand Down Expand Up @@ -96,14 +97,6 @@ func NewCmdAgent() *cobra.Command {
os.Exit(1)
}

// get klusterlet
kl := ocmoperator.Klusterlet{}
err = mgr.GetAPIReader().Get(context.Background(), client.ObjectKey{Name: "klusterlet"}, &kl)
if err != nil {
klog.Fatalf("unable to get klusterlet: %v", err)
os.Exit(1)
}

hubManager, err := manager.New(hubConfig, manager.Options{
Scheme: scheme,
Metrics: metricsserver.Options{BindAddress: "0"},
Expand All @@ -113,12 +106,12 @@ func NewCmdAgent() *cobra.Command {
ByObject: map[client.Object]cache.ByObject{
&authorizationv1alpha1.ManagedClusterRoleBinding{}: {
Namespaces: map[string]cache.Config{
kl.Spec.ClusterName: {},
spokeClusterName: {},
},
},
&authorizationv1alpha1.ManagedClusterRole{}: {
Namespaces: map[string]cache.Config{
kl.Spec.ClusterName: {},
spokeClusterName: {},
},
},
},
Expand All @@ -140,7 +133,7 @@ func NewCmdAgent() *cobra.Command {
if err := (&controller.ManagedClusterRoleReconciler{
HubClient: hubManager.GetClient(),
SpokeClient: mgr.GetClient(),
ClusterName: kl.Spec.ClusterName,
ClusterName: spokeClusterName,
}).SetupWithManager(hubManager); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ManagedClusterRoleReconciler")
os.Exit(1)
Expand Down Expand Up @@ -181,6 +174,7 @@ func NewCmdAgent() *cobra.Command {
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.StringVar(&hubKC, "hub-kubeconfig", "", "Path to hub kubeconfig")
flag.StringVar(&spokeClusterName, "cluster-name", "", "Spoke cluster name")

fs := flag.NewFlagSet("zap", flag.ExitOnError)
opts.BindFlags(fs)
Expand Down
4 changes: 4 additions & 0 deletions pkg/manager/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func GetDefaultValues(registryFQDN string) addonfactory.GetValuesFunc {
return nil, err
}

if err = unstructured.SetNestedField(values, cluster.Name, "clusterName"); err != nil {
return nil, err
}

return values, nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ spec:
{{- if .Values.hubKubeconfigSecretName }}
- --hub-kubeconfig=/var/run/secrets/ocm/auth/kubeconfig
{{- end }}
{{- if .Values.clusterName }}
- --cluster-name={{ .Values.clusterName }}
{{- end }}
ports:
- containerPort: 8080
env:
Expand Down
3 changes: 3 additions & 0 deletions pkg/manager/agent-manifests/cluster-auth/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,6 @@ apiServer:

# Name of OCM Hub Kubeconfig secret
hubKubeconfigSecretName: ""

# We need to pass the cluster name because the OCM-MC host cluster doesn't have Klusterlet object.
clusterName: ""

0 comments on commit 26db7e4

Please sign in to comment.