diff --git a/pkg/kubenest/constants/constant.go b/pkg/kubenest/constants/constant.go index 182139f34..d3a436a11 100644 --- a/pkg/kubenest/constants/constant.go +++ b/pkg/kubenest/constants/constant.go @@ -39,7 +39,7 @@ const ( //controlplane apiserver ApiServer = "apiserver" ApiServerReplicas = 2 - ApiServerServiceSubnet = "10.237.6.18/29" + ApiServerServiceSubnet = "10.237.6.0/18" ApiServerEtcdListenClientPort = 2379 ApiServerServiceType = "NodePort" // APICallRetryInterval defines how long kubeadm should wait before retrying a failed API operation diff --git a/pkg/kubenest/controlplane/component.go b/pkg/kubenest/controlplane/component.go index bbf1dd848..54aa8bb6f 100644 --- a/pkg/kubenest/controlplane/component.go +++ b/pkg/kubenest/controlplane/component.go @@ -12,8 +12,8 @@ import ( "k8s.io/klog/v2" "github.com/kosmos.io/kosmos/pkg/kubenest/constants" - controller "github.com/kosmos.io/kosmos/pkg/kubenest/manifest/controlplane/kube-controller" - scheduler "github.com/kosmos.io/kosmos/pkg/kubenest/manifest/controlplane/scheduler" + controller "github.com/kosmos.io/kosmos/pkg/kubenest/manifest/controlplane/kubecontroller" + "github.com/kosmos.io/kosmos/pkg/kubenest/manifest/controlplane/scheduler" "github.com/kosmos.io/kosmos/pkg/kubenest/util" ) @@ -115,9 +115,9 @@ func getComponentConfigmaps(component string) []string { func getKubeControllerManagerManifest(name, namespace string) (*appsv1.Deployment, error) { imageRepository, imageVersion := util.GetImageMessage() kubeControllerManagerBytes, err := util.ParseTemplate(controller.KubeControllerManagerDeployment, struct { - DeploymentName, Namespace, ImageRepository, Version string - VirtualClusterCertsSecret, KubeconfigSecret string - Replicas int32 + DeploymentName, Namespace, ImageRepository, Version string + VirtualClusterCertsSecret, KubeconfigSecret, ServiceSubnet string + Replicas int32 }{ DeploymentName: fmt.Sprintf("%s-%s", name, "kube-controller-manager"), Namespace: namespace, @@ -125,6 +125,7 @@ func getKubeControllerManagerManifest(name, namespace string) (*appsv1.Deploymen Version: imageVersion, VirtualClusterCertsSecret: fmt.Sprintf("%s-%s", name, "cert"), KubeconfigSecret: fmt.Sprintf("%s-%s", name, "admin-config"), + ServiceSubnet: constants.ApiServerServiceSubnet, Replicas: constants.KubeControllerReplicas, }) if err != nil { @@ -147,15 +148,15 @@ func getVirtualClusterSchedulerConfigMapManifest(name, namespace string) (*v1.Co Namespace: namespace, }) if err != nil { - return nil, fmt.Errorf("error when parsing virtualCluster-scheduler configMap template: %w", err) + return nil, fmt.Errorf("error when parsing virtualCluster scheduler configMap template: %w", err) } - scheduler := &v1.ConfigMap{} - if err := kuberuntime.DecodeInto(clientsetscheme.Codecs.UniversalDecoder(), virtualClusterSchedulerConfigMapBytes, scheduler); err != nil { + config := &v1.ConfigMap{} + if err := kuberuntime.DecodeInto(clientsetscheme.Codecs.UniversalDecoder(), virtualClusterSchedulerConfigMapBytes, config); err != nil { return nil, fmt.Errorf("err when decoding virtualCluster-scheduler configMap: %w", err) } - return scheduler, nil + return config, nil } func getVirtualClusterSchedulerManifest(name, namespace string) (*appsv1.Deployment, error) { @@ -177,10 +178,10 @@ func getVirtualClusterSchedulerManifest(name, namespace string) (*appsv1.Deploym return nil, fmt.Errorf("error when parsing virtualCluster-scheduler deployment template: %w", err) } - scheduler := &appsv1.Deployment{} - if err := kuberuntime.DecodeInto(clientsetscheme.Codecs.UniversalDecoder(), virtualClusterSchedulerBytes, scheduler); err != nil { + deploy := &appsv1.Deployment{} + if err := kuberuntime.DecodeInto(clientsetscheme.Codecs.UniversalDecoder(), virtualClusterSchedulerBytes, deploy); err != nil { return nil, fmt.Errorf("err when decoding virtualCluster-scheduler deployment: %w", err) } - return scheduler, nil + return deploy, nil } diff --git a/pkg/kubenest/controlplane/rbac.go b/pkg/kubenest/controlplane/rbac.go index 23a01efe0..a208e64d0 100644 --- a/pkg/kubenest/controlplane/rbac.go +++ b/pkg/kubenest/controlplane/rbac.go @@ -9,7 +9,7 @@ import ( clientset "k8s.io/client-go/kubernetes" clientsetscheme "k8s.io/client-go/kubernetes/scheme" - "github.com/kosmos.io/kosmos/pkg/kubenest/manifest/controlplane/rbac" + "github.com/kosmos.io/kosmos/pkg/kubenest/manifest/controlplane/scheduler" "github.com/kosmos.io/kosmos/pkg/kubenest/util" ) @@ -27,7 +27,7 @@ func EnsureVirtualSchedulerRBAC(client clientset.Interface, namespace string) er } func grantVirtualClusterResourceClusterSA(client clientset.Interface, namespace string) error { - virtualClusterResourceClusterSABytes, err := util.ParseTemplate(rbac.VirtualSchedulerSA, struct { + virtualClusterResourceClusterSABytes, err := util.ParseTemplate(scheduler.VirtualSchedulerSA, struct { Namespace string }{ Namespace: namespace, @@ -43,7 +43,7 @@ func grantVirtualClusterResourceClusterSA(client clientset.Interface, namespace } func grantVirtualClusterResourceClusterRoleBinding(client clientset.Interface, namespace string) error { - virtualClusterResourceClusterRoleBindingBytes, err := util.ParseTemplate(rbac.VirtualSchedulerRoleBinding, struct { + virtualClusterResourceClusterRoleBindingBytes, err := util.ParseTemplate(scheduler.VirtualSchedulerRoleBinding, struct { Namespace string }{ Namespace: namespace, @@ -61,7 +61,7 @@ func grantVirtualClusterResourceClusterRoleBinding(client clientset.Interface, n func grantVirtualClusterResourceClusterRole(client clientset.Interface) error { viewClusterrole := &rbacv1.ClusterRole{} - if err := kuberuntime.DecodeInto(clientsetscheme.Codecs.UniversalDecoder(), []byte(rbac.VirtualSchedulerRole), viewClusterrole); err != nil { + if err := kuberuntime.DecodeInto(clientsetscheme.Codecs.UniversalDecoder(), []byte(scheduler.VirtualSchedulerRole), viewClusterrole); err != nil { return fmt.Errorf("err when decoding virtualCluster scheduler Clusterrole: %w", err) } return util.CreateOrUpdateClusterRole(client, viewClusterrole) diff --git a/pkg/kubenest/manifest/controlplane/kube-controller/manifests_deployment.go b/pkg/kubenest/manifest/controlplane/kubecontroller/manifests_deployment.go similarity index 97% rename from pkg/kubenest/manifest/controlplane/kube-controller/manifests_deployment.go rename to pkg/kubenest/manifest/controlplane/kubecontroller/manifests_deployment.go index 67eaf6f5b..ee863c737 100644 --- a/pkg/kubenest/manifest/controlplane/kube-controller/manifests_deployment.go +++ b/pkg/kubenest/manifest/controlplane/kubecontroller/manifests_deployment.go @@ -1,4 +1,4 @@ -package kube_controller +package kubecontroller const ( // KubeControllerManagerDeployment is KubeControllerManage deployment manifest @@ -66,7 +66,7 @@ spec: - --node-cidr-mask-size=24 - --root-ca-file=/etc/virtualcluster/pki/ca.crt - --service-account-private-key-file=/etc/virtualcluster/pki/virtualCluster.key - - --service-cluster-ip-range=10.96.0.0/12 + - --service-cluster-ip-range={{ .ServiceSubnet }} - --use-service-account-credentials=true - --v=4 livenessProbe: diff --git a/pkg/kubenest/manifest/controlplane/scheduler/manifest_configmap.go b/pkg/kubenest/manifest/controlplane/scheduler/manifest_configmap.go index 9225def24..6cd4f6eb0 100644 --- a/pkg/kubenest/manifest/controlplane/scheduler/manifest_configmap.go +++ b/pkg/kubenest/manifest/controlplane/scheduler/manifest_configmap.go @@ -1,4 +1,4 @@ -package kube_controller +package scheduler const ( VirtualClusterSchedulerConfigMap = ` diff --git a/pkg/kubenest/manifest/controlplane/scheduler/manifest_deployment.go b/pkg/kubenest/manifest/controlplane/scheduler/manifest_deployment.go index 05013d9c7..11843d5be 100644 --- a/pkg/kubenest/manifest/controlplane/scheduler/manifest_deployment.go +++ b/pkg/kubenest/manifest/controlplane/scheduler/manifest_deployment.go @@ -1,4 +1,4 @@ -package kube_controller +package scheduler const ( VirtualClusterSchedulerDeployment = ` diff --git a/pkg/kubenest/manifest/controlplane/rbac/manifests_rbac.go b/pkg/kubenest/manifest/controlplane/scheduler/manifests_rbac.go similarity index 99% rename from pkg/kubenest/manifest/controlplane/rbac/manifests_rbac.go rename to pkg/kubenest/manifest/controlplane/scheduler/manifests_rbac.go index 050e55a6e..2680eba2b 100644 --- a/pkg/kubenest/manifest/controlplane/rbac/manifests_rbac.go +++ b/pkg/kubenest/manifest/controlplane/scheduler/manifests_rbac.go @@ -1,4 +1,4 @@ -package rbac +package scheduler const ( VirtualSchedulerSA = `