@@ -94,15 +94,15 @@ type joinFederation struct {
94
94
}
95
95
96
96
type joinFederationOptions struct {
97
- secretName string
98
- scope apiextv1.ResourceScope
99
- errorOnExisting bool
97
+ hostClusterSecretName string
98
+ scope apiextv1.ResourceScope
99
+ errorOnExisting bool
100
100
}
101
101
102
102
// Bind adds the join specific arguments to the flagset passed in as an
103
103
// argument.
104
104
func (o * joinFederationOptions ) Bind (flags * pflag.FlagSet ) {
105
- flags .StringVar (& o .secretName , "secret-name" , "" ,
105
+ flags .StringVar (& o .hostClusterSecretName , "secret-name" , "" ,
106
106
"Name of the secret where the cluster's credentials will be stored in the host cluster. This name should be a valid RFC 1035 label. If unspecified, defaults to a generated name containing the cluster name." )
107
107
flags .BoolVar (& o .errorOnExisting , "error-on-existing" , true ,
108
108
"Whether the join operation will throw an error if it encounters existing artifacts with the same name as those it's trying to create. If false, the join operation will update existing artifacts to match its own specification." )
@@ -161,7 +161,7 @@ func (j *joinFederation) Complete(args []string) error {
161
161
162
162
klog .V (2 ).Infof ("Args and flags: name %s, host: %s, host-system-namespace: %s, kubeconfig: %s, cluster-context: %s, secret-name: %s, dry-run: %v" ,
163
163
j .ClusterName , j .HostClusterContext , j .KubeFedNamespace , j .Kubeconfig , j .ClusterContext ,
164
- j .secretName , j .DryRun )
164
+ j .hostClusterSecretName , j .DryRun )
165
165
166
166
return nil
167
167
}
@@ -198,7 +198,7 @@ func (j *joinFederation) Run(cmdOut io.Writer, config util.FedConfig) error {
198
198
}
199
199
200
200
_ , err = JoinCluster (hostConfig , clusterConfig , j .KubeFedNamespace ,
201
- hostClusterName , j .ClusterName , j .secretName , j .joinFederationOptions .scope , j .DryRun , j .errorOnExisting )
201
+ hostClusterName , j .ClusterName , j .hostClusterSecretName , j .joinFederationOptions .scope , j .DryRun , j .errorOnExisting )
202
202
203
203
return err
204
204
}
@@ -207,18 +207,18 @@ func (j *joinFederation) Run(cmdOut io.Writer, config util.FedConfig) error {
207
207
// KubeFed namespace in the joining cluster will be the same as in the
208
208
// host cluster.
209
209
func JoinCluster (hostConfig , clusterConfig * rest.Config , kubefedNamespace ,
210
- hostClusterName , joiningClusterName , secretName string ,
210
+ hostClusterName , joiningClusterName , hostClusterSecretName string ,
211
211
scope apiextv1.ResourceScope , dryRun , errorOnExisting bool ) (* fedv1b1.KubeFedCluster , error ) {
212
212
return joinClusterForNamespace (hostConfig , clusterConfig , kubefedNamespace ,
213
- kubefedNamespace , hostClusterName , joiningClusterName , secretName ,
213
+ kubefedNamespace , hostClusterName , joiningClusterName , hostClusterSecretName ,
214
214
scope , dryRun , errorOnExisting )
215
215
}
216
216
217
217
// joinClusterForNamespace registers a cluster with a KubeFed control
218
218
// plane. The KubeFed namespace in the joining cluster is provided by
219
219
// the joiningNamespace parameter.
220
220
func joinClusterForNamespace (hostConfig , clusterConfig * rest.Config , kubefedNamespace ,
221
- joiningNamespace , hostClusterName , joiningClusterName , secretName string ,
221
+ joiningNamespace , hostClusterName , joiningClusterName , hostClusterSecretName string ,
222
222
scope apiextv1.ResourceScope , dryRun , errorOnExisting bool ) (* fedv1b1.KubeFedCluster , error ) {
223
223
start := time .Now ()
224
224
@@ -255,15 +255,16 @@ func joinClusterForNamespace(hostConfig, clusterConfig *rest.Config, kubefedName
255
255
}
256
256
klog .V (2 ).Infof ("Created %s namespace in joining cluster" , joiningNamespace )
257
257
258
- saName , err := createAuthorizedServiceAccount (clusterClientset ,
258
+ joiningClusterSATokenSecretName , err := createAuthorizedServiceAccount (clusterClientset ,
259
259
joiningNamespace , joiningClusterName , hostClusterName ,
260
260
scope , dryRun , errorOnExisting )
261
261
if err != nil {
262
262
return nil , err
263
263
}
264
264
265
265
secret , caBundle , err := populateSecretInHostCluster (clusterClientset , hostClientset ,
266
- saName , kubefedNamespace , joiningNamespace , joiningClusterName , secretName , dryRun , errorOnExisting )
266
+ joiningClusterSATokenSecretName , kubefedNamespace , joiningNamespace , joiningClusterName ,
267
+ hostClusterSecretName , dryRun , errorOnExisting )
267
268
if err != nil {
268
269
klog .V (2 ).Infof ("Error creating secret in host cluster: %s due to: %v" , hostClusterName , err )
269
270
return nil , err
@@ -424,7 +425,7 @@ func createKubeFedNamespace(clusterClientset kubeclient.Interface, kubefedNamesp
424
425
// account is returned on success.
425
426
func createAuthorizedServiceAccount (joiningClusterClientset kubeclient.Interface ,
426
427
namespace , joiningClusterName , hostClusterName string ,
427
- scope apiextv1.ResourceScope , dryRun , errorOnExisting bool ) (string , error ) {
428
+ scope apiextv1.ResourceScope , dryRun , errorOnExisting bool ) (saTokenSecretName string , err error ) {
428
429
klog .V (2 ).Infof ("Creating service account in joining cluster: %s" , joiningClusterName )
429
430
430
431
saName , err := createServiceAccount (joiningClusterClientset , namespace ,
@@ -437,15 +438,15 @@ func createAuthorizedServiceAccount(joiningClusterClientset kubeclient.Interface
437
438
438
439
klog .V (2 ).Infof ("Created service account: %s in joining cluster: %s" , saName , joiningClusterName )
439
440
440
- secretName , err : = createServiceAccountTokenSecret (saName , joiningClusterClientset , namespace ,
441
+ saTokenSecretName , err = createServiceAccountTokenSecret (saName , joiningClusterClientset , namespace ,
441
442
joiningClusterName , hostClusterName , dryRun , errorOnExisting )
442
443
if err != nil {
443
- klog .V (2 ).Infof ("Error creating service account: %s in joining cluster: %s due to: %v" ,
444
+ klog .V (2 ).Infof ("Error creating service account token secret : %s in joining cluster: %s due to: %v" ,
444
445
saName , joiningClusterName , err )
445
446
return "" , err
446
447
}
447
448
448
- klog .V (2 ).Infof ("Created service account token secret: %s in joining cluster: %s" , secretName , joiningClusterName )
449
+ klog .V (2 ).Infof ("Created service account token secret: %s in joining cluster: %s" , saTokenSecretName , joiningClusterName )
449
450
450
451
if scope == apiextv1 .NamespaceScoped {
451
452
klog .V (2 ).Infof ("Creating role and binding for service account: %s in joining cluster: %s" , saName , joiningClusterName )
@@ -485,7 +486,7 @@ func createAuthorizedServiceAccount(joiningClusterClientset kubeclient.Interface
485
486
saName , joiningClusterName )
486
487
}
487
488
488
- return saName , nil
489
+ return saTokenSecretName , nil
489
490
}
490
491
491
492
// createServiceAccount creates a service account in the cluster associated
@@ -523,7 +524,9 @@ func createServiceAccount(clusterClientset kubeclient.Interface, namespace,
523
524
default :
524
525
return saName , nil
525
526
}
526
- } // createServiceAccount creates a service account in the cluster associated
527
+ }
528
+
529
+ // createServiceAccount creates a service account in the cluster associated
527
530
// with clusterClientset with credentials that will be used by the host cluster
528
531
// to access its API server.
529
532
func createServiceAccountTokenSecret (saName string , clusterClientset kubeclient.Interface , namespace ,
@@ -880,7 +883,7 @@ func createHealthCheckClusterRoleAndBinding(clientset kubeclient.Interface, saNa
880
883
// hostClientset, putting it in a secret named secretName in the provided
881
884
// namespace.
882
885
func populateSecretInHostCluster (clusterClientset , hostClientset kubeclient.Interface ,
883
- saName , hostNamespace , joiningNamespace , joiningClusterName , secretName string ,
886
+ saTokenSecretName , hostNamespace , joiningNamespace , joiningClusterName , secretName string ,
884
887
dryRun bool , errorOnExisting bool ) (* corev1.Secret , []byte , error ) {
885
888
klog .V (2 ).Infof ("Creating cluster credentials secret in host cluster" )
886
889
@@ -892,9 +895,10 @@ func populateSecretInHostCluster(clusterClientset, hostClientset kubeclient.Inte
892
895
893
896
// Get the secret from the joining cluster.
894
897
var secret * corev1.Secret
898
+
895
899
err := wait .PollImmediate (1 * time .Second , serviceAccountSecretTimeout , func () (bool , error ) {
896
900
joiningClusterSASecret , err := clusterClientset .CoreV1 ().Secrets (joiningNamespace ).Get (
897
- context .Background (), saName , metav1.GetOptions {},
901
+ context .Background (), saTokenSecretName , metav1.GetOptions {},
898
902
)
899
903
if err != nil {
900
904
return false , nil
0 commit comments