Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reactor code and fix some bug #511

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
25 changes: 13 additions & 12 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 {
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) {
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
Loading