unify namespace and name style
Signed-off-by: cleverhu <shouping.hu@daocloud.io>
This commit is contained in:
parent
8aa58ec6cf
commit
e1e1616197
|
@ -194,7 +194,7 @@ func (c *CertRotationController) syncCertRotation(secret *corev1.Secret) error {
|
||||||
|
|
||||||
secret.Data["karmada-kubeconfig"] = karmadaKubeconfigBytes
|
secret.Data["karmada-kubeconfig"] = karmadaKubeconfigBytes
|
||||||
// Update the karmada-kubeconfig secret in the member cluster.
|
// Update the karmada-kubeconfig secret in the member cluster.
|
||||||
if _, err := c.ClusterClient.KubeClient.CoreV1().Secrets(secret.ObjectMeta.Namespace).Update(context.TODO(), secret, metav1.UpdateOptions{}); err != nil {
|
if _, err := c.ClusterClient.KubeClient.CoreV1().Secrets(secret.Namespace).Update(context.TODO(), secret, metav1.UpdateOptions{}); err != nil {
|
||||||
return fmt.Errorf("Unable to update secret, err: %w", err)
|
return fmt.Errorf("Unable to update secret, err: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,12 +19,12 @@ import (
|
||||||
// CreateService creates a Service if the target resource doesn't exist.
|
// CreateService creates a Service if the target resource doesn't exist.
|
||||||
// If the resource exists already, return directly
|
// If the resource exists already, return directly
|
||||||
func CreateService(client kubeclient.Interface, service *corev1.Service) error {
|
func CreateService(client kubeclient.Interface, service *corev1.Service) error {
|
||||||
if _, err := client.CoreV1().Services(service.ObjectMeta.Namespace).Create(context.TODO(), service, metav1.CreateOptions{}); err != nil {
|
if _, err := client.CoreV1().Services(service.Namespace).Create(context.TODO(), service, metav1.CreateOptions{}); err != nil {
|
||||||
if !apierrors.IsAlreadyExists(err) {
|
if !apierrors.IsAlreadyExists(err) {
|
||||||
return fmt.Errorf("unable to create Service: %v", err)
|
return fmt.Errorf("unable to create Service: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
klog.Warningf("Service %s is existed, creation process will skip", service.ObjectMeta.Name)
|
klog.Warningf("Service %s is existed, creation process will skip", service.Name)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ func CreateOrUpdateSecret(client kubeclient.Interface, secret *corev1.Secret) er
|
||||||
|
|
||||||
secret.ResourceVersion = existSecret.ResourceVersion
|
secret.ResourceVersion = existSecret.ResourceVersion
|
||||||
|
|
||||||
if _, err := client.CoreV1().Secrets(secret.ObjectMeta.Namespace).Update(context.TODO(), secret, metav1.UpdateOptions{}); err != nil {
|
if _, err := client.CoreV1().Secrets(secret.Namespace).Update(context.TODO(), secret, metav1.UpdateOptions{}); err != nil {
|
||||||
return fmt.Errorf("unable to update Secret: %v", err)
|
return fmt.Errorf("unable to update Secret: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ func CreateOrUpdateDeployment(client kubeclient.Interface, deploy *appsv1.Deploy
|
||||||
|
|
||||||
deploy.ResourceVersion = existDeployment.ResourceVersion
|
deploy.ResourceVersion = existDeployment.ResourceVersion
|
||||||
|
|
||||||
if _, err := client.AppsV1().Deployments(deploy.ObjectMeta.Namespace).Update(context.TODO(), deploy, metav1.UpdateOptions{}); err != nil {
|
if _, err := client.AppsV1().Deployments(deploy.Namespace).Update(context.TODO(), deploy, metav1.UpdateOptions{}); err != nil {
|
||||||
return fmt.Errorf("unable to update Deployment: %v", err)
|
return fmt.Errorf("unable to update Deployment: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ func CreateOrUpdateAPIService(apiRegistrationClient *aggregator.Clientset, apise
|
||||||
return fmt.Errorf("unable to create APIService: %v", err)
|
return fmt.Errorf("unable to create APIService: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
existAPIService, err := apiRegistrationClient.ApiregistrationV1().APIServices().Get(context.TODO(), apiservice.ObjectMeta.Name, metav1.GetOptions{})
|
existAPIService, err := apiRegistrationClient.ApiregistrationV1().APIServices().Get(context.TODO(), apiservice.Name, metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ func CreateOrUpdateAPIService(apiRegistrationClient *aggregator.Clientset, apise
|
||||||
// CreateOrUpdateRole creates a Role if the target resource doesn't exist.
|
// CreateOrUpdateRole creates a Role if the target resource doesn't exist.
|
||||||
// If the resource exists already, this function will update the resource instead.
|
// If the resource exists already, this function will update the resource instead.
|
||||||
func CreateOrUpdateRole(client kubeclient.Interface, role *rbacv1.Role) error {
|
func CreateOrUpdateRole(client kubeclient.Interface, role *rbacv1.Role) error {
|
||||||
if _, err := client.RbacV1().Roles(role.ObjectMeta.Namespace).Create(context.TODO(), role, metav1.CreateOptions{}); err != nil {
|
if _, err := client.RbacV1().Roles(role.Namespace).Create(context.TODO(), role, metav1.CreateOptions{}); err != nil {
|
||||||
if !apierrors.IsAlreadyExists(err) {
|
if !apierrors.IsAlreadyExists(err) {
|
||||||
return fmt.Errorf("unable to create RBAC role: %v", err)
|
return fmt.Errorf("unable to create RBAC role: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -112,11 +112,11 @@ func CreateOrUpdateRole(client kubeclient.Interface, role *rbacv1.Role) error {
|
||||||
|
|
||||||
role.ResourceVersion = existRole.ResourceVersion
|
role.ResourceVersion = existRole.ResourceVersion
|
||||||
|
|
||||||
if _, err := client.RbacV1().Roles(role.ObjectMeta.Namespace).Update(context.TODO(), role, metav1.UpdateOptions{}); err != nil {
|
if _, err := client.RbacV1().Roles(role.Namespace).Update(context.TODO(), role, metav1.UpdateOptions{}); err != nil {
|
||||||
return fmt.Errorf("unable to update RBAC role: %v", err)
|
return fmt.Errorf("unable to update RBAC role: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
klog.V(2).Infof("Role %s/%s has been created or updated.", role.ObjectMeta.Namespace, role.ObjectMeta.Name)
|
klog.V(2).Infof("Role %s/%s has been created or updated.", role.Namespace, role.Name)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ func CreateOrUpdateRole(client kubeclient.Interface, role *rbacv1.Role) error {
|
||||||
// CreateOrUpdateRoleBinding creates a RoleBinding if the target resource doesn't exist.
|
// CreateOrUpdateRoleBinding creates a RoleBinding if the target resource doesn't exist.
|
||||||
// If the resource exists already, this function will update the resource instead.
|
// If the resource exists already, this function will update the resource instead.
|
||||||
func CreateOrUpdateRoleBinding(client kubeclient.Interface, roleBinding *rbacv1.RoleBinding) error {
|
func CreateOrUpdateRoleBinding(client kubeclient.Interface, roleBinding *rbacv1.RoleBinding) error {
|
||||||
if _, err := client.RbacV1().RoleBindings(roleBinding.ObjectMeta.Namespace).Create(context.TODO(), roleBinding, metav1.CreateOptions{}); err != nil {
|
if _, err := client.RbacV1().RoleBindings(roleBinding.Namespace).Create(context.TODO(), roleBinding, metav1.CreateOptions{}); err != nil {
|
||||||
if !apierrors.IsAlreadyExists(err) {
|
if !apierrors.IsAlreadyExists(err) {
|
||||||
return fmt.Errorf("unable to create RBAC rolebinding: %v", err)
|
return fmt.Errorf("unable to create RBAC rolebinding: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -136,11 +136,11 @@ func CreateOrUpdateRoleBinding(client kubeclient.Interface, roleBinding *rbacv1.
|
||||||
|
|
||||||
roleBinding.ResourceVersion = existRoleBinding.ResourceVersion
|
roleBinding.ResourceVersion = existRoleBinding.ResourceVersion
|
||||||
|
|
||||||
if _, err := client.RbacV1().RoleBindings(roleBinding.ObjectMeta.Namespace).Update(context.TODO(), roleBinding, metav1.UpdateOptions{}); err != nil {
|
if _, err := client.RbacV1().RoleBindings(roleBinding.Namespace).Update(context.TODO(), roleBinding, metav1.UpdateOptions{}); err != nil {
|
||||||
return fmt.Errorf("unable to update RBAC rolebinding: %v", err)
|
return fmt.Errorf("unable to update RBAC rolebinding: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
klog.V(2).Infof("RoleBinding %s/%s has been created or updated.", roleBinding.ObjectMeta.Namespace, roleBinding.ObjectMeta.Name)
|
klog.V(2).Infof("RoleBinding %s/%s has been created or updated.", roleBinding.Namespace, roleBinding.Name)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ func CreateOrUpdateClusterRoleBinding(client kubernetes.Interface, clusterRoleBi
|
||||||
// CreateOrUpdateConfigMap creates a ConfigMap if the target resource doesn't exist.
|
// CreateOrUpdateConfigMap creates a ConfigMap if the target resource doesn't exist.
|
||||||
// If the resource exists already, this function will update the resource instead.
|
// If the resource exists already, this function will update the resource instead.
|
||||||
func CreateOrUpdateConfigMap(client *kubeclient.Clientset, cm *corev1.ConfigMap) error {
|
func CreateOrUpdateConfigMap(client *kubeclient.Clientset, cm *corev1.ConfigMap) error {
|
||||||
if _, err := client.CoreV1().ConfigMaps(cm.ObjectMeta.Namespace).Create(context.TODO(), cm, metav1.CreateOptions{}); err != nil {
|
if _, err := client.CoreV1().ConfigMaps(cm.Namespace).Create(context.TODO(), cm, metav1.CreateOptions{}); err != nil {
|
||||||
if !apierrors.IsAlreadyExists(err) {
|
if !apierrors.IsAlreadyExists(err) {
|
||||||
return fmt.Errorf("unable to create ConfigMap: %v", err)
|
return fmt.Errorf("unable to create ConfigMap: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -208,11 +208,11 @@ func CreateOrUpdateConfigMap(client *kubeclient.Clientset, cm *corev1.ConfigMap)
|
||||||
|
|
||||||
cm.ResourceVersion = existCm.ResourceVersion
|
cm.ResourceVersion = existCm.ResourceVersion
|
||||||
|
|
||||||
if _, err := client.CoreV1().ConfigMaps(cm.ObjectMeta.Namespace).Update(context.TODO(), cm, metav1.UpdateOptions{}); err != nil {
|
if _, err := client.CoreV1().ConfigMaps(cm.Namespace).Update(context.TODO(), cm, metav1.UpdateOptions{}); err != nil {
|
||||||
return fmt.Errorf("unable to update ConfigMap: %v", err)
|
return fmt.Errorf("unable to update ConfigMap: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
klog.V(2).Infof("ConfigMap %s/%s has been created or updated.", cm.ObjectMeta.Namespace, cm.ObjectMeta.Name)
|
klog.V(2).Infof("ConfigMap %s/%s has been created or updated.", cm.Namespace, cm.Name)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -245,7 +245,7 @@ func CreateOrUpdateNamespace(client kubeclient.Interface, ns *corev1.Namespace)
|
||||||
return fmt.Errorf("unable to update Namespace: %v", err)
|
return fmt.Errorf("unable to update Namespace: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
klog.Infof("Namespace %s has been created or updated.", ns.ObjectMeta.Name)
|
klog.Infof("Namespace %s has been created or updated.", ns.Name)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -265,11 +265,11 @@ func CreateOrUpdateService(client kubernetes.Interface, svc *corev1.Service) err
|
||||||
|
|
||||||
svc.ResourceVersion = existSvc.ResourceVersion
|
svc.ResourceVersion = existSvc.ResourceVersion
|
||||||
|
|
||||||
if _, err := client.CoreV1().Services(svc.ObjectMeta.Namespace).Update(context.TODO(), svc, metav1.UpdateOptions{}); err != nil {
|
if _, err := client.CoreV1().Services(svc.Namespace).Update(context.TODO(), svc, metav1.UpdateOptions{}); err != nil {
|
||||||
return fmt.Errorf("unable to update Service: %v", err)
|
return fmt.Errorf("unable to update Service: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
klog.Infof("Service %s/%s has been created or updated.", svc.ObjectMeta.Namespace, svc.ObjectMeta.Name)
|
klog.Infof("Service %s/%s has been created or updated.", svc.Namespace, svc.Name)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ func DeleteNamespace(client kubeclient.Interface, namespace string) error {
|
||||||
// If namespace not exit, just create it.
|
// If namespace not exit, just create it.
|
||||||
func EnsureNamespaceExist(client kubeclient.Interface, namespace string, dryRun bool) (*corev1.Namespace, error) {
|
func EnsureNamespaceExist(client kubeclient.Interface, namespace string, dryRun bool) (*corev1.Namespace, error) {
|
||||||
namespaceObj := &corev1.Namespace{}
|
namespaceObj := &corev1.Namespace{}
|
||||||
namespaceObj.ObjectMeta.Name = namespace
|
namespaceObj.Name = namespace
|
||||||
|
|
||||||
if dryRun {
|
if dryRun {
|
||||||
return namespaceObj, nil
|
return namespaceObj, nil
|
||||||
|
|
|
@ -173,7 +173,7 @@ func CreateOrUpdateClusterRole(client kubeclient.Interface, clusterRole *rbacv1.
|
||||||
return fmt.Errorf("unable to update RBAC clusterrole: %v", err)
|
return fmt.Errorf("unable to update RBAC clusterrole: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
klog.V(1).Infof("ClusterRole %s has been created or updated.", clusterRole.ObjectMeta.Name)
|
klog.V(1).Infof("ClusterRole %s has been created or updated.", clusterRole.Name)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,7 @@ func CreateOrUpdateClusterRoleBinding(client kubeclient.Interface, clusterRoleBi
|
||||||
return fmt.Errorf("unable to update RBAC clusterrolebinding: %v", err)
|
return fmt.Errorf("unable to update RBAC clusterrolebinding: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
klog.V(1).Infof("ClusterRoleBinding %s has been created or updated.", clusterRoleBinding.ObjectMeta.Name)
|
klog.V(1).Infof("ClusterRoleBinding %s has been created or updated.", clusterRoleBinding.Name)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -275,7 +275,7 @@ var _ = ginkgo.Describe("[karmada-search] karmada search testing", ginkgo.Ordere
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
rr.ObjectMeta.Name = rrName
|
rr.Name = rrName
|
||||||
framework.CreateResourceRegistry(karmadaClient, rr)
|
framework.CreateResourceRegistry(karmadaClient, rr)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@ var _ = ginkgo.Describe("[karmada-search] karmada search testing", ginkgo.Ordere
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
rr.ObjectMeta.Name = rrName
|
rr.Name = rrName
|
||||||
framework.CreateResourceRegistry(karmadaClient, rr)
|
framework.CreateResourceRegistry(karmadaClient, rr)
|
||||||
searchObject(pathAllDaemonsets, existsDaemonsetName, true)
|
searchObject(pathAllDaemonsets, existsDaemonsetName, true)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue