Skip to content

Commit

Permalink
Merge pull request #1451 from sayaoailun/release-1.1
Browse files Browse the repository at this point in the history
cherry-pick #1416: `karmadactl`: Fixed `--namespace` flag of `init` command not work issue.
  • Loading branch information
karmada-bot committed Mar 9, 2022
2 parents 0b73c6b + a7ce6cd commit 231a860
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
16 changes: 8 additions & 8 deletions pkg/karmadactl/cmdinit/karmada/deploy.go
Expand Up @@ -28,7 +28,7 @@ import (
const namespace = "karmada-system"

// InitKarmadaResources Initialize karmada resource
func InitKarmadaResources(dir, caBase64 string) error {
func InitKarmadaResources(dir, caBase64 string, systemNamespace string) error {
restConfig, err := utils.RestConfig(filepath.Join(dir, options.KarmadaKubeConfigName))
if err != nil {
return err
Expand Down Expand Up @@ -79,18 +79,18 @@ func InitKarmadaResources(dir, caBase64 string) error {

// create webhook configuration
// https://github.com/karmada-io/karmada/blob/master/artifacts/deploy/webhook-configuration.yaml
klog.Info("Crate MutatingWebhookConfiguration mutating-config.")
if err = createMutatingWebhookConfiguration(clientSet, mutatingConfig(caBase64)); err != nil {
klog.Info("Create MutatingWebhookConfiguration mutating-config.")
if err = createMutatingWebhookConfiguration(clientSet, mutatingConfig(caBase64, systemNamespace)); err != nil {
klog.Exitln(err)
}
klog.Info("Crate ValidatingWebhookConfiguration validating-config.")
klog.Info("Create ValidatingWebhookConfiguration validating-config.")

if err = createValidatingWebhookConfiguration(clientSet, validatingConfig(caBase64)); err != nil {
if err = createValidatingWebhookConfiguration(clientSet, validatingConfig(caBase64, systemNamespace)); err != nil {
klog.Exitln(err)
}

// karmada-aggregated-apiserver
if err = initAPIService(clientSet, restConfig); err != nil {
if err = initAPIService(clientSet, restConfig, systemNamespace); err != nil {
klog.Exitln(err)
}

Expand Down Expand Up @@ -162,7 +162,7 @@ func getName(str, start, end string) string {
return str
}

func initAPIService(clientSet *kubernetes.Clientset, restConfig *rest.Config) error {
func initAPIService(clientSet *kubernetes.Clientset, restConfig *rest.Config, externalNamespace string) error {
// https://github.com/karmada-io/karmada/blob/master/artifacts/deploy/apiservice.yaml
aaService := &corev1.Service{
TypeMeta: metav1.TypeMeta{
Expand All @@ -175,7 +175,7 @@ func initAPIService(clientSet *kubernetes.Clientset, restConfig *rest.Config) er
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeExternalName,
ExternalName: fmt.Sprintf("karmada-aggregated-apiserver.%s.svc.cluster.local", namespace),
ExternalName: fmt.Sprintf("karmada-aggregated-apiserver.%s.svc", externalNamespace),
},
}
if _, err := clientSet.CoreV1().Services(namespace).Create(context.TODO(), aaService, metav1.CreateOptions{}); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/karmadactl/cmdinit/karmada/webhook_configuration.go
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/karmada-io/karmada/pkg/karmadactl/cmdinit/utils"
)

func mutatingConfig(caBundle string) string {
func mutatingConfig(caBundle string, systemNamespace string) string {
return fmt.Sprintf(`apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
Expand Down Expand Up @@ -76,10 +76,10 @@ webhooks:
failurePolicy: Fail
sideEffects: None
admissionReviewVersions: ["v1"]
timeoutSeconds: 3`, namespace, caBundle, namespace, caBundle, namespace, caBundle, namespace, caBundle)
timeoutSeconds: 3`, systemNamespace, caBundle, systemNamespace, caBundle, systemNamespace, caBundle, systemNamespace, caBundle)
}

func validatingConfig(caBundle string) string {
func validatingConfig(caBundle string, systemNamespace string) string {
return fmt.Sprintf(`apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
Expand Down Expand Up @@ -156,7 +156,7 @@ webhooks:
failurePolicy: Fail
sideEffects: None
admissionReviewVersions: ["v1"]
timeoutSeconds: 3`, namespace, caBundle, namespace, caBundle, namespace, caBundle, namespace, caBundle, namespace, caBundle)
timeoutSeconds: 3`, systemNamespace, caBundle, systemNamespace, caBundle, systemNamespace, caBundle, systemNamespace, caBundle, systemNamespace, caBundle)
}

func createValidatingWebhookConfiguration(c *kubernetes.Clientset, staticYaml string) error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/karmadactl/cmdinit/kubernetes/deploy.go
Expand Up @@ -416,7 +416,7 @@ func (i *CommandInitOption) RunInit(_ io.Writer, parentCommand string) error {

// Create CRDs in karmada
caBase64 := base64.StdEncoding.EncodeToString(i.CertAndKeyFileData[fmt.Sprintf("%s.crt", options.CaCertAndKeyName)])
if err := karmada.InitKarmadaResources(i.KarmadaDataPath, caBase64); err != nil {
if err := karmada.InitKarmadaResources(i.KarmadaDataPath, caBase64, i.Namespace); err != nil {
return err
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/karmadactl/cmdinit/kubernetes/deployments.go
Expand Up @@ -11,6 +11,7 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"

"github.com/karmada-io/karmada/pkg/karmadactl/cmdinit/options"
"github.com/karmada-io/karmada/pkg/util"
)

const (
Expand Down Expand Up @@ -268,7 +269,7 @@ func (i *CommandInitOption) makeKarmadaKubeControllerManagerDeployment() *appsv1
"--controllers=namespace,garbagecollector,serviceaccount-token",
"--kubeconfig=/etc/kubeconfig",
"--leader-elect=true",
fmt.Sprintf("--leader-elect-resource-namespace=%s", i.Namespace),
fmt.Sprintf("--leader-elect-resource-namespace=%s", util.NamespaceKarmadaSystem),
"--node-cidr-mask-size=24",
"--port=0",
fmt.Sprintf("--root-ca-file=%s/%s.crt", karmadaCertsVolumeMountPath, options.CaCertAndKeyName),
Expand Down Expand Up @@ -389,7 +390,7 @@ func (i *CommandInitOption) makeKarmadaSchedulerDeployment() *appsv1.Deployment
"--feature-gates=Failover=true",
"--enable-scheduler-estimator=true",
"--leader-elect=true",
fmt.Sprintf("--leader-elect-resource-namespace=%s", i.Namespace),
fmt.Sprintf("--leader-elect-resource-namespace=%s", util.NamespaceKarmadaSystem),
"--v=4",
},
VolumeMounts: []corev1.VolumeMount{
Expand Down

0 comments on commit 231a860

Please sign in to comment.