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

standardize the naming of karmada config in karmadactl method #5797

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 6 additions & 7 deletions pkg/karmadactl/addons/descheduler/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ spec:
imagePullPolicy: IfNotPresent
command:
- /bin/karmada-descheduler
- --kubeconfig=/etc/kubeconfig
- --kubeconfig=/etc/karmada/config/karmada.config
- --metrics-bind-address=0.0.0.0:8080
- --health-probe-bind-address=0.0.0.0:10358
- --leader-elect-resource-namespace={{ .Namespace }}
Expand All @@ -66,19 +66,18 @@ spec:
name: metrics
protocol: TCP
volumeMounts:
- name: karmada-config
mountPath: /etc/karmada/config
- name: k8s-certs
mountPath: /etc/karmada/pki
readOnly: true
- name: kubeconfig
subPath: kubeconfig
mountPath: /etc/kubeconfig
volumes:
- name: karmada-config
secret:
secretName: karmada-descheduler-config
- name: k8s-certs
secret:
secretName: karmada-cert
- name: kubeconfig
secret:
secretName: kubeconfig
`

// DeploymentReplace is a struct to help to concrete
Expand Down
49 changes: 30 additions & 19 deletions pkg/karmadactl/addons/init/enable_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"k8s.io/klog/v2"
"k8s.io/utils/strings/slices"

cmdinit "github.com/karmada-io/karmada/pkg/karmadactl/cmdinit/kubernetes"
"github.com/karmada-io/karmada/pkg/karmadactl/cmdinit/options"
"github.com/karmada-io/karmada/pkg/karmadactl/util/apiclient"
"github.com/karmada-io/karmada/pkg/version"
)
Expand Down Expand Up @@ -148,10 +148,17 @@ func (o *CommandAddonsEnableOption) Validate(args []string) error {
}

secretClient := o.KubeClientSet.CoreV1().Secrets(o.Namespace)
_, err = secretClient.Get(context.TODO(), cmdinit.KubeConfigSecretAndMountName, metav1.GetOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
return fmt.Errorf("secrets `kubeconfig` is not found in namespace %s, please execute karmadactl init to deploy karmada first", o.Namespace)
for _, addon := range getEnableAddons(args) {
if addon.Name == EstimatorResourceName {
// estimator not rely on karmada config secret
continue
}
karmadaConfigSecretName := addon.Name + options.KarmadaConfigSecretSuffix
_, err = secretClient.Get(context.TODO(), karmadaConfigSecretName, metav1.GetOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
return fmt.Errorf("secrets `%s` is not found in namespace %s, please execute karmadactl init to deploy karmada first", karmadaConfigSecretName, o.Namespace)
}
}
}

Expand Down Expand Up @@ -187,21 +194,8 @@ func (o *CommandAddonsEnableOption) Validate(args []string) error {

// Run start enable Karmada addons
func (o *CommandAddonsEnableOption) Run(args []string) error {
var enableAddons = map[string]*Addon{}

// collect enabled addons
for _, item := range args {
if item == "all" {
enableAddons = Addons
break
}
if addon := Addons[item]; addon != nil {
enableAddons[item] = addon
}
}

// enable addons
for name, addon := range enableAddons {
for name, addon := range getEnableAddons(args) {
klog.Infof("Start to enable addon %s", name)
if err := addon.Enable(o); err != nil {
klog.Errorf("Install addon %s failed", name)
Expand Down Expand Up @@ -229,3 +223,20 @@ func validAddonNames(addonNames []string) error {
}
return nil
}

func getEnableAddons(addonNames []string) map[string]*Addon {
var enableAddons = map[string]*Addon{}

// collect enabled addons
for _, item := range addonNames {
if item == "all" {
enableAddons = Addons
break
}
if addon := Addons[item]; addon != nil {
enableAddons[item] = addon
}
}

return enableAddons
}
25 changes: 12 additions & 13 deletions pkg/karmadactl/addons/metricsadapter/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,11 @@ spec:
- name: karmada-metrics-adapter
image: {{ .Image }}
imagePullPolicy: IfNotPresent
volumeMounts:
- name: k8s-certs
mountPath: /etc/karmada/pki
readOnly: true
- name: kubeconfig
subPath: kubeconfig
mountPath: /etc/kubeconfig
command:
- /bin/karmada-metrics-adapter
- --kubeconfig=/etc/kubeconfig
- --authentication-kubeconfig=/etc/kubeconfig
- --authorization-kubeconfig=/etc/kubeconfig
- --kubeconfig=/etc/karmada/config/karmada.config
- --authentication-kubeconfig=/etc/karmada/config/karmada.config
- --authorization-kubeconfig=/etc/karmada/config/karmada.config
- --client-ca-file=/etc/karmada/pki/ca.crt
- --audit-log-path=-
- --audit-log-maxage=0
Expand All @@ -81,13 +74,19 @@ spec:
resources:
requests:
cpu: 100m
volumeMounts:
- name: karmada-config
mountPath: /etc/karmada/config
- name: k8s-certs
mountPath: /etc/karmada/pki
readOnly: true
volumes:
- name: karmada-config
secret:
secretName: karmada-metrics-adapter-config
- name: k8s-certs
secret:
secretName: karmada-cert
- name: kubeconfig
secret:
secretName: kubeconfig
`

karmadaMetricsAdapterService = `
Expand Down
25 changes: 12 additions & 13 deletions pkg/karmadactl/addons/search/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,11 @@ spec:
- name: karmada-search
image: {{ .Image }}
imagePullPolicy: IfNotPresent
volumeMounts:
- name: k8s-certs
mountPath: /etc/karmada/pki
readOnly: true
- name: kubeconfig
subPath: kubeconfig
mountPath: /etc/kubeconfig
command:
- /bin/karmada-search
- --kubeconfig=/etc/kubeconfig
- --authentication-kubeconfig=/etc/kubeconfig
- --authorization-kubeconfig=/etc/kubeconfig
- --kubeconfig=/etc/karmada/config/karmada.config
- --authentication-kubeconfig=/etc/karmada/config/karmada.config
- --authorization-kubeconfig=/etc/karmada/config/karmada.config
- --etcd-servers={{ .ETCDSevers }}
- --etcd-cafile=/etc/karmada/pki/etcd-ca.crt
- --etcd-certfile=/etc/karmada/pki/etcd-client.crt
Expand All @@ -78,13 +71,19 @@ spec:
resources:
requests:
cpu: 100m
volumeMounts:
- name: karmada-config
mountPath: /etc/karmada/config
- name: k8s-certs
mountPath: /etc/karmada/pki
readOnly: true
volumes:
- name: karmada-config
secret:
secretName: karmada-search-config
- name: k8s-certs
secret:
secretName: karmada-cert
- name: kubeconfig
secret:
secretName: kubeconfig
`

karmadaSearchService = `
Expand Down
22 changes: 18 additions & 4 deletions pkg/karmadactl/cmdinit/kubernetes/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ var (
options.FrontProxyClientCertAndKeyName,
}

karmadaConfigList = []string{
options.KarmadaAggregatedApiserverConfig,
options.KarmadaControllerManagerConfig,
options.KubeControllerManagerConfig,
options.KarmadaSchedulerConfig,
options.KarmadaDeschedulerConfig,
options.KarmadaMetricsAdapterConfig,
options.KarmadaSearchConfig,
options.KarmadaWebhookConfig,
}

emptyByteSlice = make([]byte, 0)
externalEtcdCertSpecialization = map[string]func(*CommandInitOption) ([]byte, []byte, error){
options.EtcdCaCertAndKeyName: func(option *CommandInitOption) (cert, key []byte, err error) {
Expand Down Expand Up @@ -397,7 +408,7 @@ func (i *CommandInitOption) prepareCRD() error {
}

func (i *CommandInitOption) createCertsSecrets() error {
// Create kubeconfig Secret
// 1. Create karmada-config Secret
karmadaServerURL := fmt.Sprintf("https://%s.%s.svc.%s:%v", karmadaAPIServerDeploymentAndServiceName, i.Namespace, i.HostClusterDomain, karmadaAPIServerContainerPort)
config := utils.CreateWithCerts(karmadaServerURL, options.UserName, options.UserName, i.CertAndKeyFileData[fmt.Sprintf("%s.crt", globaloptions.CaCertAndKeyName)],
i.CertAndKeyFileData[fmt.Sprintf("%s.key", options.KarmadaCertAndKeyName)], i.CertAndKeyFileData[fmt.Sprintf("%s.crt", options.KarmadaCertAndKeyName)])
Expand All @@ -406,10 +417,13 @@ func (i *CommandInitOption) createCertsSecrets() error {
return fmt.Errorf("failure while serializing admin kubeConfig. %v", err)
}

kubeConfigSecret := i.SecretFromSpec(KubeConfigSecretAndMountName, corev1.SecretTypeOpaque, map[string]string{KubeConfigSecretAndMountName: string(configBytes)})
if err = util.CreateOrUpdateSecret(i.KubeClientSet, kubeConfigSecret); err != nil {
return err
for _, karmadaConfigSecretName := range karmadaConfigList {
kubeConfigSecret := i.SecretFromSpec(karmadaConfigSecretName, corev1.SecretTypeOpaque, map[string]string{options.KarmadaConfigFieldName: string(configBytes)})
if err = util.CreateOrUpdateSecret(i.KubeClientSet, kubeConfigSecret); err != nil {
return err
}
}

// Create certs Secret
etcdCert := map[string]string{
fmt.Sprintf("%s.crt", options.EtcdCaCertAndKeyName): string(i.CertAndKeyFileData[fmt.Sprintf("%s.crt", options.EtcdCaCertAndKeyName)]),
Expand Down
Loading
Loading