Merge pull request #1416 from sayaoailun/master
`karmadactl`: Fixed `--namespace` flag of `init` command not work issue.
This commit is contained in:
commit
7ed9c62651
|
@ -29,7 +29,7 @@ import (
|
||||||
const namespace = "karmada-system"
|
const namespace = "karmada-system"
|
||||||
|
|
||||||
// InitKarmadaResources Initialize karmada resource
|
// 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))
|
restConfig, err := utils.RestConfig(filepath.Join(dir, options.KarmadaKubeConfigName))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -80,18 +80,18 @@ func InitKarmadaResources(dir, caBase64 string) error {
|
||||||
|
|
||||||
// create webhook configuration
|
// create webhook configuration
|
||||||
// https://github.com/karmada-io/karmada/blob/master/artifacts/deploy/webhook-configuration.yaml
|
// https://github.com/karmada-io/karmada/blob/master/artifacts/deploy/webhook-configuration.yaml
|
||||||
klog.Info("Crate MutatingWebhookConfiguration mutating-config.")
|
klog.Info("Create MutatingWebhookConfiguration mutating-config.")
|
||||||
if err = createMutatingWebhookConfiguration(clientSet, mutatingConfig(caBase64)); err != nil {
|
if err = createMutatingWebhookConfiguration(clientSet, mutatingConfig(caBase64, systemNamespace)); err != nil {
|
||||||
klog.Exitln(err)
|
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)
|
klog.Exitln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// karmada-aggregated-apiserver
|
// karmada-aggregated-apiserver
|
||||||
if err = initAPIService(clientSet, restConfig); err != nil {
|
if err = initAPIService(clientSet, restConfig, systemNamespace); err != nil {
|
||||||
klog.Exitln(err)
|
klog.Exitln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ func getName(str, start, end string) string {
|
||||||
return str
|
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
|
// https://github.com/karmada-io/karmada/blob/master/artifacts/deploy/apiservice.yaml
|
||||||
aaService := &corev1.Service{
|
aaService := &corev1.Service{
|
||||||
TypeMeta: metav1.TypeMeta{
|
TypeMeta: metav1.TypeMeta{
|
||||||
|
@ -176,7 +176,7 @@ func initAPIService(clientSet *kubernetes.Clientset, restConfig *rest.Config) er
|
||||||
},
|
},
|
||||||
Spec: corev1.ServiceSpec{
|
Spec: corev1.ServiceSpec{
|
||||||
Type: corev1.ServiceTypeExternalName,
|
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 {
|
if _, err := clientSet.CoreV1().Services(namespace).Create(context.TODO(), aaService, metav1.CreateOptions{}); err != nil {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"github.com/karmada-io/karmada/pkg/karmadactl/cmdinit/utils"
|
"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
|
return fmt.Sprintf(`apiVersion: admissionregistration.k8s.io/v1
|
||||||
kind: MutatingWebhookConfiguration
|
kind: MutatingWebhookConfiguration
|
||||||
metadata:
|
metadata:
|
||||||
|
@ -76,10 +76,10 @@ webhooks:
|
||||||
failurePolicy: Fail
|
failurePolicy: Fail
|
||||||
sideEffects: None
|
sideEffects: None
|
||||||
admissionReviewVersions: ["v1"]
|
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
|
return fmt.Sprintf(`apiVersion: admissionregistration.k8s.io/v1
|
||||||
kind: ValidatingWebhookConfiguration
|
kind: ValidatingWebhookConfiguration
|
||||||
metadata:
|
metadata:
|
||||||
|
@ -156,7 +156,7 @@ webhooks:
|
||||||
failurePolicy: Fail
|
failurePolicy: Fail
|
||||||
sideEffects: None
|
sideEffects: None
|
||||||
admissionReviewVersions: ["v1"]
|
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 {
|
func createValidatingWebhookConfiguration(c *kubernetes.Clientset, staticYaml string) error {
|
||||||
|
|
|
@ -417,7 +417,7 @@ func (i *CommandInitOption) RunInit(_ io.Writer, parentCommand string) error {
|
||||||
|
|
||||||
// Create CRDs in karmada
|
// Create CRDs in karmada
|
||||||
caBase64 := base64.StdEncoding.EncodeToString(i.CertAndKeyFileData[fmt.Sprintf("%s.crt", options.CaCertAndKeyName)])
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/util/intstr"
|
"k8s.io/apimachinery/pkg/util/intstr"
|
||||||
|
|
||||||
"github.com/karmada-io/karmada/pkg/karmadactl/cmdinit/options"
|
"github.com/karmada-io/karmada/pkg/karmadactl/cmdinit/options"
|
||||||
|
"github.com/karmada-io/karmada/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -268,7 +269,7 @@ func (i *CommandInitOption) makeKarmadaKubeControllerManagerDeployment() *appsv1
|
||||||
"--controllers=namespace,garbagecollector,serviceaccount-token",
|
"--controllers=namespace,garbagecollector,serviceaccount-token",
|
||||||
"--kubeconfig=/etc/kubeconfig",
|
"--kubeconfig=/etc/kubeconfig",
|
||||||
"--leader-elect=true",
|
"--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",
|
"--node-cidr-mask-size=24",
|
||||||
"--port=0",
|
"--port=0",
|
||||||
fmt.Sprintf("--root-ca-file=%s/%s.crt", karmadaCertsVolumeMountPath, options.CaCertAndKeyName),
|
fmt.Sprintf("--root-ca-file=%s/%s.crt", karmadaCertsVolumeMountPath, options.CaCertAndKeyName),
|
||||||
|
@ -389,7 +390,7 @@ func (i *CommandInitOption) makeKarmadaSchedulerDeployment() *appsv1.Deployment
|
||||||
"--feature-gates=Failover=true",
|
"--feature-gates=Failover=true",
|
||||||
"--enable-scheduler-estimator=true",
|
"--enable-scheduler-estimator=true",
|
||||||
"--leader-elect=true",
|
"--leader-elect=true",
|
||||||
fmt.Sprintf("--leader-elect-resource-namespace=%s", i.Namespace),
|
fmt.Sprintf("--leader-elect-resource-namespace=%s", util.NamespaceKarmadaSystem),
|
||||||
"--v=4",
|
"--v=4",
|
||||||
},
|
},
|
||||||
VolumeMounts: []corev1.VolumeMount{
|
VolumeMounts: []corev1.VolumeMount{
|
||||||
|
|
Loading…
Reference in New Issue