add karmada apiserver kubeconfig to karmada status

Signed-off-by: calvin <wen.chen@daocloud.io>
This commit is contained in:
calvin 2023-07-13 15:32:44 +08:00
parent be9a371e75
commit 6d3bd8d507
6 changed files with 42 additions and 29 deletions

View File

@ -4,12 +4,14 @@ import (
"context" "context"
"fmt" "fmt"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
"k8s.io/klog/v2" "k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client"
operator "github.com/karmada-io/karmada/operator/pkg" operator "github.com/karmada-io/karmada/operator/pkg"
operatorv1alpha1 "github.com/karmada-io/karmada/operator/pkg/apis/operator/v1alpha1" operatorv1alpha1 "github.com/karmada-io/karmada/operator/pkg/apis/operator/v1alpha1"
"github.com/karmada-io/karmada/operator/pkg/util"
"github.com/karmada-io/karmada/operator/pkg/workflow" "github.com/karmada-io/karmada/operator/pkg/workflow"
) )
@ -111,13 +113,24 @@ func (p *Planner) preRunJob() error {
} }
func (p *Planner) runJobErr(err error) error { func (p *Planner) runJobErr(err error) error {
var errs []error
errs = append(errs, err)
operatorv1alpha1.KarmadaFailed(p.karmada, operatorv1alpha1.Ready, err.Error()) operatorv1alpha1.KarmadaFailed(p.karmada, operatorv1alpha1.Ready, err.Error())
return p.Client.Status().Update(context.TODO(), p.karmada) errs = append(errs, p.Client.Status().Update(context.TODO(), p.karmada))
return utilerrors.NewAggregate(errs)
} }
func (p *Planner) afterRunJob() error { func (p *Planner) afterRunJob() error {
if p.action == InitAction { if p.action == InitAction {
// Update the condition to Ready and set kubeconfig of karmada-apiserver to status.
operatorv1alpha1.KarmadaCompleted(p.karmada, operatorv1alpha1.Ready, "karmada init job is completed") operatorv1alpha1.KarmadaCompleted(p.karmada, operatorv1alpha1.Ready, "karmada init job is completed")
p.karmada.Status.SecretRef = &operatorv1alpha1.LocalSecretReference{
Namespace: p.karmada.GetNamespace(),
Name: util.AdminKubeconfigSecretName(p.karmada.GetName()),
}
return p.Client.Status().Update(context.TODO(), p.karmada) return p.Client.Status().Update(context.TODO(), p.karmada)
} }

View File

@ -158,9 +158,9 @@ spec:
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
command: command:
- /bin/karmada-aggregated-apiserver - /bin/karmada-aggregated-apiserver
- --kubeconfig=/etc/karmada/config - --kubeconfig=/etc/karmada/kubeconfig
- --authentication-kubeconfig=/etc/karmada/config - --authentication-kubeconfig=/etc/karmada/kubeconfig
- --authorization-kubeconfig=/etc/karmada/config - --authorization-kubeconfig=/etc/karmada/kubeconfig
- --etcd-cafile=/etc/etcd/pki/etcd-ca.crt - --etcd-cafile=/etc/etcd/pki/etcd-ca.crt
- --etcd-certfile=/etc/etcd/pki/etcd-client.crt - --etcd-certfile=/etc/etcd/pki/etcd-client.crt
- --etcd-keyfile=/etc/etcd/pki/etcd-client.key - --etcd-keyfile=/etc/etcd/pki/etcd-client.key
@ -172,9 +172,9 @@ spec:
- --audit-log-maxage=0 - --audit-log-maxage=0
- --audit-log-maxbackup=0 - --audit-log-maxbackup=0
volumeMounts: volumeMounts:
- mountPath: /etc/karmada/config - mountPath: /etc/karmada/kubeconfig
name: kubeconfig name: kubeconfig
subPath: config subPath: kubeconfig
- mountPath: /etc/etcd/pki - mountPath: /etc/etcd/pki
name: etcd-cert name: etcd-cert
readOnly: true readOnly: true

View File

@ -39,9 +39,9 @@ spec:
command: command:
- kube-controller-manager - kube-controller-manager
- --allocate-node-cidrs=true - --allocate-node-cidrs=true
- --kubeconfig=/etc/karmada/config - --kubeconfig=/etc/karmada/kubeconfig
- --authentication-kubeconfig=/etc/karmada/config - --authentication-kubeconfig=/etc/karmada/kubeconfig
- --authorization-kubeconfig=/etc/karmada/config - --authorization-kubeconfig=/etc/karmada/kubeconfig
- --bind-address=0.0.0.0 - --bind-address=0.0.0.0
- --client-ca-file=/etc/karmada/pki/ca.crt - --client-ca-file=/etc/karmada/pki/ca.crt
- --cluster-cidr=10.244.0.0/16 - --cluster-cidr=10.244.0.0/16
@ -71,8 +71,8 @@ spec:
mountPath: /etc/karmada/pki mountPath: /etc/karmada/pki
readOnly: true readOnly: true
- name: kubeconfig - name: kubeconfig
mountPath: /etc/karmada/config mountPath: /etc/karmada/kubeconfig
subPath: config subPath: kubeconfig
volumes: volumes:
- name: karmada-certs - name: karmada-certs
secret: secret:
@ -111,7 +111,7 @@ spec:
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
command: command:
- /bin/karmada-controller-manager - /bin/karmada-controller-manager
- --kubeconfig=/etc/karmada/config - --kubeconfig=/etc/karmada/kubeconfig
- --bind-address=0.0.0.0 - --bind-address=0.0.0.0
- --cluster-status-update-frequency=10s - --cluster-status-update-frequency=10s
- --secure-port=10357 - --secure-port=10357
@ -129,8 +129,8 @@ spec:
timeoutSeconds: 5 timeoutSeconds: 5
volumeMounts: volumeMounts:
- name: kubeconfig - name: kubeconfig
subPath: config subPath: kubeconfig
mountPath: /etc/karmada/config mountPath: /etc/karmada/kubeconfig
volumes: volumes:
- name: kubeconfig - name: kubeconfig
secret: secret:
@ -167,7 +167,7 @@ spec:
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
command: command:
- /bin/karmada-scheduler - /bin/karmada-scheduler
- --kubeconfig=/etc/karmada/config - --kubeconfig=/etc/karmada/kubeconfig
- --bind-address=0.0.0.0 - --bind-address=0.0.0.0
- --secure-port=10351 - --secure-port=10351
- --enable-scheduler-estimator=true - --enable-scheduler-estimator=true
@ -184,8 +184,8 @@ spec:
timeoutSeconds: 5 timeoutSeconds: 5
volumeMounts: volumeMounts:
- name: kubeconfig - name: kubeconfig
subPath: config subPath: kubeconfig
mountPath: /etc/karmada/config mountPath: /etc/karmada/kubeconfig
volumes: volumes:
- name: kubeconfig - name: kubeconfig
secret: secret:
@ -222,7 +222,7 @@ spec:
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
command: command:
- /bin/karmada-descheduler - /bin/karmada-descheduler
- --kubeconfig=/etc/karmada/config - --kubeconfig=/etc/karmada/kubeconfig
- --bind-address=0.0.0.0 - --bind-address=0.0.0.0
- --leader-elect-resource-namespace={{ .SystemNamespace }} - --leader-elect-resource-namespace={{ .SystemNamespace }}
- --v=4 - --v=4
@ -237,8 +237,8 @@ spec:
timeoutSeconds: 5 timeoutSeconds: 5
volumeMounts: volumeMounts:
- name: kubeconfig - name: kubeconfig
subPath: config subPath: kubeconfig
mountPath: /etc/karmada/config mountPath: /etc/karmada/kubeconfig
volumes: volumes:
- name: kubeconfig - name: kubeconfig
secret: secret:

View File

@ -31,17 +31,17 @@ spec:
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
command: command:
- /bin/karmada-metrics-adapter - /bin/karmada-metrics-adapter
- --kubeconfig=/etc/karmada/config - --kubeconfig=/etc/karmada/kubeconfig
- --authentication-kubeconfig=/etc/karmada/config - --authentication-kubeconfig=/etc/karmada/kubeconfig
- --authorization-kubeconfig=/etc/karmada/config - --authorization-kubeconfig=/etc/karmada/kubeconfig
- --client-ca-file=/etc/karmada/pki/ca.crt - --client-ca-file=/etc/karmada/pki/ca.crt
- --audit-log-path=- - --audit-log-path=-
- --audit-log-maxage=0 - --audit-log-maxage=0
- --audit-log-maxbackup=0 - --audit-log-maxbackup=0
volumeMounts: volumeMounts:
- name: kubeconfig - name: kubeconfig
subPath: config subPath: kubeconfig
mountPath: /etc/karmada/config mountPath: /etc/karmada/kubeconfig
- name: karmada-cert - name: karmada-cert
mountPath: /etc/karmada/pki mountPath: /etc/karmada/pki
readOnly: true readOnly: true

View File

@ -31,7 +31,7 @@ spec:
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
command: command:
- /bin/karmada-webhook - /bin/karmada-webhook
- --kubeconfig=/etc/karmada/config - --kubeconfig=/etc/karmada/kubeconfig
- --bind-address=0.0.0.0 - --bind-address=0.0.0.0
- --default-not-ready-toleration-seconds=30 - --default-not-ready-toleration-seconds=30
- --default-unreachable-toleration-seconds=30 - --default-unreachable-toleration-seconds=30
@ -42,8 +42,8 @@ spec:
- containerPort: 8443 - containerPort: 8443
volumeMounts: volumeMounts:
- name: kubeconfig - name: kubeconfig
subPath: config subPath: kubeconfig
mountPath: /etc/karmada/config mountPath: /etc/karmada/kubeconfig
- name: cert - name: cert
mountPath: /var/serving-cert mountPath: /var/serving-cert
readOnly: true readOnly: true

View File

@ -80,7 +80,7 @@ func runUploadAdminKubeconfig(r workflow.RunData) error {
Name: util.AdminKubeconfigSecretName(data.GetName()), Name: util.AdminKubeconfigSecretName(data.GetName()),
Labels: constants.KarmadaOperatorLabel, Labels: constants.KarmadaOperatorLabel,
}, },
Data: map[string][]byte{"config": configBytes}, Data: map[string][]byte{"kubeconfig": configBytes},
}) })
if err != nil { if err != nil {
return fmt.Errorf("failed to create secret of kubeconfig, err: %w", err) return fmt.Errorf("failed to create secret of kubeconfig, err: %w", err)