|
|
|
@ -19,12 +19,12 @@ import (
|
|
|
|
|
// CreateService creates a Service if the target resource doesn't exist.
|
|
|
|
|
// If the resource exists already, return directly
|
|
|
|
|
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) {
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
@ -44,7 +44,7 @@ func CreateOrUpdateSecret(client kubeclient.Interface, secret *corev1.Secret) er
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -66,7 +66,7 @@ func CreateOrUpdateDeployment(client kubeclient.Interface, deploy *appsv1.Deploy
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -81,7 +81,7 @@ func CreateOrUpdateAPIService(apiRegistrationClient *aggregator.Clientset, apise
|
|
|
|
|
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 {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
@ -100,7 +100,7 @@ func CreateOrUpdateAPIService(apiRegistrationClient *aggregator.Clientset, apise
|
|
|
|
|
// CreateOrUpdateRole creates a Role if the target resource doesn't exist.
|
|
|
|
|
// If the resource exists already, this function will update the resource instead.
|
|
|
|
|
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) {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
@ -124,7 +124,7 @@ func CreateOrUpdateRole(client kubeclient.Interface, role *rbacv1.Role) error {
|
|
|
|
|
// CreateOrUpdateRoleBinding creates a RoleBinding if the target resource doesn't exist.
|
|
|
|
|
// If the resource exists already, this function will update the resource instead.
|
|
|
|
|
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) {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
@ -196,7 +196,7 @@ func CreateOrUpdateClusterRoleBinding(client kubernetes.Interface, clusterRoleBi
|
|
|
|
|
// CreateOrUpdateConfigMap creates a ConfigMap if the target resource doesn't exist.
|
|
|
|
|
// If the resource exists already, this function will update the resource instead.
|
|
|
|
|
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) {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
@ -245,7 +245,7 @@ func CreateOrUpdateNamespace(client kubeclient.Interface, ns *corev1.Namespace)
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
@ -265,11 +265,11 @@ func CreateOrUpdateService(client kubernetes.Interface, svc *corev1.Service) err
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|