Skip to content

Commit b4a71b4

Browse files
Pass spoke cluster name to the agent (#29)
Signed-off-by: Rokibul Hasan <mdrokibulhasan@appscode.com>
1 parent 53eb16c commit b4a71b4

18 files changed

+25
-2585
lines changed

pkg/apiserver/apiserver.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import (
5151
cu "kmodules.xyz/client-go/client"
5252
clustermeta "kmodules.xyz/client-go/cluster"
5353
clusterv1alpha1 "open-cluster-management.io/api/cluster/v1alpha1"
54-
ocmoperator "open-cluster-management.io/api/operator/v1"
5554
"sigs.k8s.io/controller-runtime/pkg/cache"
5655
"sigs.k8s.io/controller-runtime/pkg/client"
5756
"sigs.k8s.io/controller-runtime/pkg/log"
@@ -71,7 +70,6 @@ func init() {
7170
proxyserverinstall.Install(Scheme)
7271
utilruntime.Must(clientgoscheme.AddToScheme(Scheme))
7372
utilruntime.Must(clusterv1alpha1.Install(Scheme))
74-
utilruntime.Must(ocmoperator.Install(Scheme))
7573
utilruntime.Must(core.AddToScheme(Scheme))
7674

7775
// we need to add the options to empty v1
@@ -91,12 +89,13 @@ func init() {
9189

9290
// ExtraConfig holds custom apiserver config
9391
type ExtraConfig struct {
94-
ClientConfig *restclient.Config
95-
BaseURL string
96-
Token string
97-
LicenseDir string
98-
CacheDir string
99-
HubKubeconfig string
92+
ClientConfig *restclient.Config
93+
BaseURL string
94+
Token string
95+
LicenseDir string
96+
CacheDir string
97+
HubKubeconfig string
98+
SpokeClusterName string
10099
}
101100

102101
// Config defines the config for the apiserver
@@ -220,6 +219,9 @@ func (c completedConfig) New(ctx context.Context) (*LicenseProxyServer, error) {
220219
}
221220

222221
if isSpokeCluster {
222+
if c.ExtraConfig.SpokeClusterName == "" {
223+
return nil, fmt.Errorf("missing --cluster-name")
224+
}
223225
if c.ExtraConfig.HubKubeconfig == "" {
224226
return nil, fmt.Errorf("missing --hub-kubeconfig")
225227
}
@@ -248,13 +250,6 @@ func (c completedConfig) New(ctx context.Context) (*LicenseProxyServer, error) {
248250
os.Exit(1)
249251
}
250252

251-
// get klusterlet
252-
kl := ocmoperator.Klusterlet{}
253-
err = spokeManager.GetAPIReader().Get(context.Background(), client.ObjectKey{Name: "klusterlet"}, &kl)
254-
if err != nil {
255-
return nil, err
256-
}
257-
258253
// get hub kubeconfig
259254
hubConfig, err := clientcmd.BuildConfigFromFlags("", c.ExtraConfig.HubKubeconfig)
260255
if err != nil {
@@ -273,7 +268,7 @@ func (c completedConfig) New(ctx context.Context) (*LicenseProxyServer, error) {
273268
ByObject: map[client.Object]cache.ByObject{
274269
&core.Secret{}: {
275270
Namespaces: map[string]cache.Config{
276-
kl.Spec.ClusterName: {
271+
c.ExtraConfig.SpokeClusterName: {
277272
FieldSelector: fields.OneTermEqualSelector("metadata.name", common.LicenseSecret),
278273
},
279274
},

pkg/cmds/server/options.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ type ExtraOptions struct {
3131
LicenseDir string
3232
CacheDir string
3333

34-
HubKubeconfig string
34+
HubKubeconfig string
35+
SpokeClusterName string
3536
}
3637

3738
func NewExtraOptions() *ExtraOptions {
@@ -49,6 +50,7 @@ func (s *ExtraOptions) AddFlags(fs *pflag.FlagSet) {
4950
fs.StringVar(&s.LicenseDir, "license-dir", s.LicenseDir, "Path to license directory")
5051
fs.StringVar(&s.CacheDir, "cache-dir", s.CacheDir, "Path to license cache directory")
5152
fs.StringVar(&s.HubKubeconfig, "hub-kubeconfig", s.HubKubeconfig, "Path to hub kubeconfig")
53+
fs.StringVar(&s.SpokeClusterName, "cluster-name", s.SpokeClusterName, "Spoke Cluster name")
5254
}
5355

5456
func (s *ExtraOptions) ApplyTo(cfg *apiserver.ExtraConfig) error {
@@ -57,6 +59,7 @@ func (s *ExtraOptions) ApplyTo(cfg *apiserver.ExtraConfig) error {
5759
cfg.LicenseDir = s.LicenseDir
5860
cfg.CacheDir = s.CacheDir
5961
cfg.HubKubeconfig = s.HubKubeconfig
62+
cfg.SpokeClusterName = s.SpokeClusterName
6063
cfg.ClientConfig.QPS = float32(s.QPS)
6164
cfg.ClientConfig.Burst = s.Burst
6265

pkg/manager/agent-manifests/license-proxyserver/templates/cluster-role.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,3 @@ rules:
2323
resources:
2424
- clusterclaims
2525
verbs: ["get", "list", "watch", "create", "update", "patch"]
26-
# ocm cluster name detection
27-
- apiGroups:
28-
- operator.open-cluster-management.io
29-
resources:
30-
- klusterlets
31-
verbs: ["get"]

pkg/manager/agent-manifests/license-proxyserver/templates/deployment.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ spec:
5151
{{- if .Values.hubKubeconfigSecretName }}
5252
- --hub-kubeconfig=/var/run/secrets/ocm/auth/kubeconfig
5353
{{- end }}
54+
{{- if .Values.clusterName }}
55+
- --cluster-name={{ .Values.clusterName }}
56+
{{- end }}
5457
ports:
5558
- containerPort: 8443
5659
- containerPort: 8081

pkg/manager/agent-manifests/license-proxyserver/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,6 @@ encodedLicenses: {}
123123

124124
# Name of OCM Hub Kubeconfig secret
125125
hubKubeconfigSecretName: ""
126+
127+
# We need to pass the cluster name because the OCM-MC host cluster doesn't have Klusterlet object.
128+
clusterName: ""

pkg/manager/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ func GetConfigValues(opts *ManagerOptions, cs *certstore.CertStore) addonfactory
109109
if err != nil {
110110
return nil, err
111111
}
112+
err = unstructured.SetNestedField(vals, cluster.Name, "clusterName")
113+
if err != nil {
114+
return nil, err
115+
}
112116

113117
return vals, nil
114118
}

vendor/modules.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,6 @@ open-cluster-management.io/api/cluster/v1
14821482
open-cluster-management.io/api/cluster/v1alpha1
14831483
open-cluster-management.io/api/cluster/v1beta1
14841484
open-cluster-management.io/api/cluster/v1beta2
1485-
open-cluster-management.io/api/operator/v1
14861485
open-cluster-management.io/api/utils/work/v1/workapplier
14871486
open-cluster-management.io/api/work/v1
14881487
open-cluster-management.io/api/work/v1alpha1

0 commit comments

Comments
 (0)