Skip to content

Commit

Permalink
reactor code and fix some bug
Browse files Browse the repository at this point in the history
Signed-off-by: duanmengkk <[email protected]>
  • Loading branch information
duanmengkk committed May 8, 2024
1 parent ffa2dfb commit 0c584ab
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pkg/kubenest/constants/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 14 additions & 13 deletions pkg/kubenest/controlplane/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -115,16 +115,17 @@ 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,
ImageRepository: imageRepository,
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 {
Expand All @@ -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 {
return nil, fmt.Errorf("err when decoding virtualCluster-scheduler configMap: %w", err)
config := &v1.ConfigMap{}
if err := kuberuntime.DecodeInto(clientsetscheme.Codecs.UniversalDecoder(), virtualClusterSchedulerConfigMapBytes, config); err != nil {
return nil, fmt.Errorf("err when decoding virtualCluster-config configMap: %w", err)
}

return scheduler, nil
return config, nil
}

func getVirtualClusterSchedulerManifest(name, namespace string) (*appsv1.Deployment, error) {
Expand All @@ -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
}
8 changes: 4 additions & 4 deletions pkg/kubenest/controlplane/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kube_controller
package kubecontroller

const (
// KubeControllerManagerDeployment is KubeControllerManage deployment manifest
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kube_controller
package scheduler

const (
VirtualClusterSchedulerConfigMap = `
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kube_controller
package scheduler

const (
VirtualClusterSchedulerDeployment = `
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package rbac
package scheduler

const (
VirtualSchedulerSA = `
Expand Down

0 comments on commit 0c584ab

Please sign in to comment.