diff --git a/deploy/clustertree-cluster-manager.yml b/deploy/clustertree-cluster-manager.yml index baf004e61..78ff95971 100644 --- a/deploy/clustertree-cluster-manager.yml +++ b/deploy/clustertree-cluster-manager.yml @@ -35,8 +35,8 @@ metadata: namespace: kosmos-system type: Opaque data: - cert.pem: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUQzakNDQXNhZ0F3SUJBZ0lJVWE0NWVxZmI0c0V3RFFZSktvWklodmNOQVFFTEJRQXdmekVMTUFrR0ExVUUKQmhNQ1ZWTXhEekFOQmdOVkJBZ1RCazl5WldkdmJqRVJNQThHQTFVRUJ4TUlVRzl5ZEd4aGJtUXhHREFXQmdOVgpCQW9URDNacmRXSmxiR1YwTFcxdlkyc3RNREVZTUJZR0ExVUVDeE1QZG10MVltVnNaWFF0Ylc5amF5MHdNUmd3CkZnWURWUVFERXc5MmEzVmlaV3hsZEMxdGIyTnJMVEF3SGhjTk1UZ3hNVEkyTVRJd016SXpXaGNOTVRrd01qSTEKTVRnd09ESXpXakIvTVFzd0NRWURWUVFHRXdKVlV6RVBNQTBHQTFVRUNCTUdUM0psWjI5dU1SRXdEd1lEVlFRSApFd2hRYjNKMGJHRnVaREVZTUJZR0ExVUVDaE1QZG10MVltVnNaWFF0Ylc5amF5MHdNUmd3RmdZRFZRUUxFdzkyCmEzVmlaV3hsZEMxdGIyTnJMVEF4R0RBV0JnTlZCQU1URDNacmRXSmxiR1YwTFcxdlkyc3RNRENDQVNJd0RRWUoKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBTHJ5SHZLM1VCQkJxR1YyRnB3eW1mMHAvWUtHUUE5cgpOdTBONmYyK1JrVVhMdVFYRytXZEZRbDNaUXliUExmQ0UyaHdGY2wzSUYrM2hDelkzLzJVSXlHQmxvQklmdDdLCllGTE0zWVdKRHk1RWxLRGcxYk5EU0x6RjZ0a3BOTERuVmxna1BQSVR6cEVISUF1K0JUNURaR1doWUFXTy9EaXIKWGR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0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCgo= + cert.pem: __CERT__ + key.pem: __CERT__ --- apiVersion: apps/v1 @@ -66,7 +66,7 @@ spec: value: /etc/cluster-tree/cert/cert.pem - name: APISERVER_KEY_LOCATION value: /etc/cluster-tree/cert/key.pem - - name: KNODE_POD_IP + - name: LEAF_NODE_IP valueFrom: fieldRef: fieldPath: status.podIP diff --git a/hack/cluster.sh b/hack/cluster.sh index d2725d7cc..5eace5128 100755 --- a/hack/cluster.sh +++ b/hack/cluster.sh @@ -12,6 +12,10 @@ KIND_IMAGE="ghcr.io/kosmos-io/kindest/node:v1.25.3_1" REUSE=${REUSE:-false} VERSION=${VERSION:-latest} +# default cert and key for node server https +CERT="LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUQzakNDQXNhZ0F3SUJBZ0lJVWE0NWVxZmI0c0V3RFFZSktvWklodmNOQVFFTEJRQXdmekVMTUFrR0ExVUUKQmhNQ1ZWTXhEekFOQmdOVkJBZ1RCazl5WldkdmJqRVJNQThHQTFVRUJ4TUlVRzl5ZEd4aGJtUXhHREFXQmdOVgpCQW9URDNacmRXSmxiR1YwTFcxdlkyc3RNREVZTUJZR0ExVUVDeE1QZG10MVltVnNaWFF0Ylc5amF5MHdNUmd3CkZnWURWUVFERXc5MmEzVmlaV3hsZEMxdGIyTnJMVEF3SGhjTk1UZ3hNVEkyTVRJd016SXpXaGNOTVRrd01qSTEKTVRnd09ESXpXakIvTVFzd0NRWURWUVFHRXdKVlV6RVBNQTBHQTFVRUNCTUdUM0psWjI5dU1SRXdEd1lEVlFRSApFd2hRYjNKMGJHRnVaREVZTUJZR0ExVUVDaE1QZG10MVltVnNaWFF0Ylc5amF5MHdNUmd3RmdZRFZRUUxFdzkyCmEzVmlaV3hsZEMxdGIyTnJMVEF4R0RBV0JnTlZCQU1URDNacmRXSmxiR1YwTFcxdlkyc3RNRENDQVNJd0RRWUoKS29aSWh2Y05BUUVCQlFBRGdnRVB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M3ZuZUc4dmdzOEFyRWpOODlCL1l4TzFxSVU1bXhKZTZaYWZiODFOZGhZVWpmUkFWcm8KQUxUb2ZpQXBNc25EYkpESE1pd3Z3Y0RVSGJQTHBydUs4MFIvL3ptWDdYZW4rRis1b2JmU1E4ajBHU21tZVdGUQpTVkc2QXBOdGt0TFBJMG5LMm5FSUgvUXg0b3VHQzlOMHBBRFJDbFFRUFN4RVBtRHZmNHhmCi0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCgo=" + CN_ZONE=${CN_ZONE:-false} if [ $REUSE == true ]; then @@ -155,7 +159,7 @@ function deploy_cluster() { echo "cluster $clustername deploy clusterlink success" - sed -e "s|__VERSION__|$VERSION|g" -e "w ${ROOT}/environments/clustertree-cluster-manager.yml" "$ROOT"/deploy/clustertree-cluster-manager.yml + sed -e "s|__VERSION__|$VERSION|g" -e "s|__CERT__|$CERT|g" -e "s|__KEY__|$KEY|g" -e "w ${ROOT}/environments/clustertree-cluster-manager.yml" "$ROOT"/deploy/clustertree-cluster-manager.yml kubectl --context="kind-${clustername}" apply -f "${ROOT}/environments/clustertree-cluster-manager.yml" echo "cluster $clustername deploy clustertree success" diff --git a/pkg/clustertree/cluster-manager/utils/rootcluster.go b/pkg/clustertree/cluster-manager/utils/rootcluster.go index 73cf17e9a..241fcfa83 100644 --- a/pkg/clustertree/cluster-manager/utils/rootcluster.go +++ b/pkg/clustertree/cluster-manager/utils/rootcluster.go @@ -24,7 +24,7 @@ func IsRootCluster(cluster *kosmosv1alpha1.Cluster) bool { func GetAddress() []corev1.NodeAddress { address := []corev1.NodeAddress{ - {Type: corev1.NodeInternalIP, Address: os.Getenv("KNODE_POD_IP")}, + {Type: corev1.NodeInternalIP, Address: os.Getenv("LEAF_NODE_IP")}, } return address } diff --git a/pkg/kosmosctl/install/install.go b/pkg/kosmosctl/install/install.go index c3bd72288..139d15591 100644 --- a/pkg/kosmosctl/install/install.go +++ b/pkg/kosmosctl/install/install.go @@ -48,6 +48,12 @@ var installExample = templates.Examples(i18n.T(` kosmosctl install -m coredns `)) +// default cert and key for node server https +const ( + certpem = "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUQzakNDQXNhZ0F3SUJBZ0lJVWE0NWVxZmI0c0V3RFFZSktvWklodmNOQVFFTEJRQXdmekVMTUFrR0ExVUUKQmhNQ1ZWTXhEekFOQmdOVkJBZ1RCazl5WldkdmJqRVJNQThHQTFVRUJ4TUlVRzl5ZEd4aGJtUXhHREFXQmdOVgpCQW9URDNacmRXSmxiR1YwTFcxdlkyc3RNREVZTUJZR0ExVUVDeE1QZG10MVltVnNaWFF0Ylc5amF5MHdNUmd3CkZnWURWUVFERXc5MmEzVmlaV3hsZEMxdGIyTnJMVEF3SGhjTk1UZ3hNVEkyTVRJd016SXpXaGNOTVRrd01qSTEKTVRnd09ESXpXakIvTVFzd0NRWURWUVFHRXdKVlV6RVBNQTBHQTFVRUNCTUdUM0psWjI5dU1SRXdEd1lEVlFRSApFd2hRYjNKMGJHRnVaREVZTUJZR0ExVUVDaE1QZG10MVltVnNaWFF0Ylc5amF5MHdNUmd3RmdZRFZRUUxFdzkyCmEzVmlaV3hsZEMxdGIyTnJMVEF4R0RBV0JnTlZCQU1URDNacmRXSmxiR1YwTFcxdlkyc3RNRENDQVNJd0RRWUoKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBTHJ5SHZLM1VCQkJxR1YyRnB3eW1mMHAvWUtHUUE5cgpOdTBONmYyK1JrVVhMdVFYRytXZEZRbDNaUXliUExmQ0UyaHdGY2wzSUYrM2hDelkzLzJVSXlHQmxvQklmdDdLCllGTE0zWVdKRHk1RWxLRGcxYk5EU0x6RjZ0a3BOTERuVmxna1BQSVR6cEVISUF1K0JUNURaR1doWUFXTy9EaXIKWGR4b0pCT2hQWlpDY0JDVitrd1FRUGJzWHpaeStxN1FoeDI3MENSTUlYc285QzVMSmhHWUw5ZndzeG11a0FPUgo1NlNtZnNBYW1s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Options struct { K8sClient kubernetes.Interface K8sDynamicClient *dynamic.DynamicClient K8sExtensionsClient extensionsclient.Interface + + CrtEncode string + KeyEncode string } // NewCmdInstall Install the Kosmos control plane in a Kubernetes cluster. @@ -100,6 +109,9 @@ func NewCmdInstall(f ctlutil.Factory) *cobra.Command { flags.StringVar(&o.UseProxy, "use-proxy", "false", "Set whether to enable proxy.") flags.IntVarP(&o.WaitTime, "wait-time", "", utils.DefaultWaitTime, "Wait the specified time for the Kosmos install ready.") + flags.StringVar(&o.CrtEncode, "crt-encode", certpem, "crt base64 string for node server.") + flags.StringVar(&o.KeyEncode, "key-encode", keypem, "key base64 string for node server.") + return cmd } @@ -447,6 +459,23 @@ func (o *CommandInstallOptions) runClustertree() error { } klog.Info("ConfigMap host-kubeconfig has been created.") + klog.Info("Start creating kosmos-clustertree secret") + clustertreeSecret, err := util.GenerattSecret(manifest.ClusterTreeClusterManagerSecret, manifest.SecretReplace{ + Namespace: o.Namespace, + Cert: o.CrtEncode, + Key: o.KeyEncode, + }) + if err != nil { + return err + } + _, err = o.K8sClient.CoreV1().Secrets(o.Namespace).Create(context.Background(), clustertreeSecret, metav1.CreateOptions{}) + if err != nil { + if !apierrors.IsAlreadyExists(err) { + return fmt.Errorf("kosmosctl install clustertree run error, secret options failed: %v", err) + } + } + klog.Info("Secret has been created. ") + klog.Info("Start creating kosmos-clustertree Deployment...") clustertreeDeploy, err := util.GenerateDeployment(manifest.ClusterTreeClusterManagerDeployment, manifest.DeploymentReplace{ Namespace: o.Namespace, diff --git a/pkg/kosmosctl/manifest/manifest_deployments.go b/pkg/kosmosctl/manifest/manifest_deployments.go index 734b0eeaf..f888726b4 100644 --- a/pkg/kosmosctl/manifest/manifest_deployments.go +++ b/pkg/kosmosctl/manifest/manifest_deployments.go @@ -120,10 +120,27 @@ spec: - name: manager image: {{ .ImageRepository }}/clustertree-cluster-manager:v{{ .Version }} imagePullPolicy: IfNotPresent + env: + - name: APISERVER_CERT_LOCATION + value: /etc/cluster-tree/cert/cert.pem + - name: APISERVER_KEY_LOCATION + value: /etc/cluster-tree/cert/key.pem + - name: LEAF_NODE_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + volumeMounts: + - name: credentials + mountPath: "/etc/cluster-tree/cert" + readOnly: true command: - clustertree-cluster-manager - --multi-cluster-service=true - --v=4 + volumes: + - name: credentials + secret: + secretName: clustertree-cluster-manager ` CorednsDeployment = ` diff --git a/pkg/kosmosctl/manifest/manifest_secrets.go b/pkg/kosmosctl/manifest/manifest_secrets.go new file mode 100644 index 000000000..6d7aac0f0 --- /dev/null +++ b/pkg/kosmosctl/manifest/manifest_secrets.go @@ -0,0 +1,21 @@ +package manifest + +const ( + ClusterTreeClusterManagerSecret = `--- +apiVersion: v1 +kind: Secret +metadata: + name: clustertree-cluster-manager + namespace: {{ .Namespace }} +type: Opaque +data: + cert.pem: {{ .Cert }} + key.pem: {{ .Key }} +` +) + +type SecretReplace struct { + Namespace string + Cert string + Key string +} diff --git a/pkg/kosmosctl/uninstall/uninstall.go b/pkg/kosmosctl/uninstall/uninstall.go index b8a6cedc9..192041c06 100644 --- a/pkg/kosmosctl/uninstall/uninstall.go +++ b/pkg/kosmosctl/uninstall/uninstall.go @@ -319,6 +319,22 @@ func (o *CommandUninstallOptions) runClustertree() error { } } else { klog.Info("Deployment " + clustertreeDeploy.Name + " is deleted.") + clustertreeSecret, err := util.GenerateService(manifest.ClusterTreeClusterManagerSecret, manifest.SecretReplace{ + Namespace: o.Namespace, + Cert: "", + Key: "", + }) + if err != nil { + return err + } + err = o.K8sClient.CoreV1().Secrets(o.Namespace).Delete(context.Background(), clustertreeSecret.Name, metav1.DeleteOptions{}) + if err != nil { + if !apierrors.IsNotFound(err) { + return fmt.Errorf("kosmosctl uninstall clustertree secret run error, secret options failed: %v", err) + } + } else { + klog.Info("Secret " + clustertreeSecret.Name + " is deleted.") + } } clusters, err := o.KosmosClient.KosmosV1alpha1().Clusters().List(context.TODO(), metav1.ListOptions{}) diff --git a/pkg/kosmosctl/util/builder.go b/pkg/kosmosctl/util/builder.go index 7c5647c91..a36e3a393 100644 --- a/pkg/kosmosctl/util/builder.go +++ b/pkg/kosmosctl/util/builder.go @@ -179,3 +179,20 @@ func GenerateService(template string, obj interface{}) (*corev1.Service, error) } return o, nil } + +func GenerattSecret(template string, obj interface{}) (*corev1.Secret, error) { + bs, err := parseTemplate(template, obj) + if err != nil { + return nil, fmt.Errorf("kosmosctl parsing secret template exception, error: %v", err) + } else if bs == nil { + return nil, fmt.Errorf("kosmosctl get secret template exception, value is empty") + } + + o := &corev1.Secret{} + + if err = runtime.DecodeInto(scheme.Codecs.UniversalDecoder(), bs, o); err != nil { + return nil, fmt.Errorf("kosmosctl decode secret bytes error: %v", err) + } + + return o, nil +}