Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request #518 from zhuangqh/me-kubeconfig-from-vc
Browse files Browse the repository at this point in the history
[incubator][VC] syncer: try to get tenant admin kubeconfig from vc object
  • Loading branch information
k8s-ci-robot authored Mar 12, 2020
2 parents d546a72 + 468987b commit 06f32a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions incubator/virtualcluster/pkg/syncer/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const (
LabelClusterIP = "tenancy.x-k8s.io/clusterIP"
// LabelSecretName is the service account token secret name in tenant namespace.
LabelSecretName = "tenancy.x-k8s.io/secret.name"
// LabelAdminKubeConfig is the kubeconfig in base64 format for tenant master.
LabelAdminKubeConfig = "tenancy.x-k8s.io/admin-kubeconfig"

// LabelServiceAccountUID is the tenant service account UID related to the secret.
LabelServiceAccountUID = "tenancy.x-k8s.io/service-account.UID"
Expand Down
14 changes: 10 additions & 4 deletions incubator/virtualcluster/pkg/syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,18 @@ func (s *Syncer) addCluster(key string, vc *v1alpha1.Virtualcluster) error {

clusterName := conversion.ToClusterKey(vc)

adminKubeConfigSecret, err := s.secretClient.Secrets(clusterName).Get(KubeconfigAdmin, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to get secret (%s) for virtual cluster in root namespace %s: %v", KubeconfigAdmin, clusterName, err)
var adminKubeConfigBytes []byte
if adminKubeConfig, exists := vc.GetAnnotations()[constants.LabelAdminKubeConfig]; exists {
adminKubeConfigBytes = []byte(adminKubeConfig)
} else {
adminKubeConfigSecret, err := s.secretClient.Secrets(clusterName).Get(KubeconfigAdmin, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to get secret (%s) for virtual cluster in root namespace %s: %v", KubeconfigAdmin, clusterName, err)
}
adminKubeConfigBytes = adminKubeConfigSecret.Data[KubeconfigAdmin]
}

tenantCluster, err := cluster.NewTenantCluster(clusterName, vc.Namespace, vc.Name, string(vc.UID), s.lister, adminKubeConfigSecret.Data[KubeconfigAdmin], cluster.Options{})
tenantCluster, err := cluster.NewTenantCluster(clusterName, vc.Namespace, vc.Name, string(vc.UID), s.lister, adminKubeConfigBytes, cluster.Options{})
if err != nil {
return fmt.Errorf("failed to new tenant cluster %s/%s: %v", vc.Namespace, vc.Name, err)
}
Expand Down

0 comments on commit 06f32a3

Please sign in to comment.