mirror of
https://github.com/rancher/rke.git
synced 2025-08-31 14:36:32 +00:00
Refactor to new client-go API in k8s 1.18
This commit is contained in:
@@ -28,6 +28,7 @@ import (
|
|||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||||
apiserverv1alpha1 "k8s.io/apiserver/pkg/apis/apiserver/v1alpha1"
|
apiserverv1alpha1 "k8s.io/apiserver/pkg/apis/apiserver/v1alpha1"
|
||||||
@@ -970,7 +971,7 @@ func setNodeAnnotationsLabelsTaints(k8sClient *kubernetes.Clientset, host *hosts
|
|||||||
logrus.Debugf("skipping syncing labels for node [%s]", node.Name)
|
logrus.Debugf("skipping syncing labels for node [%s]", node.Name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
_, err = k8sClient.CoreV1().Nodes().Update(node)
|
_, err = k8sClient.CoreV1().Nodes().Update(context.TODO(), node, metav1.UpdateOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("Error syncing labels for node [%s]: %v", node.Name, err)
|
logrus.Debugf("Error syncing labels for node [%s]: %v", node.Name, err)
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
|
@@ -1,8 +1,11 @@
|
|||||||
package k8s
|
package k8s
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
rbacv1 "k8s.io/api/rbac/v1"
|
rbacv1 "k8s.io/api/rbac/v1"
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,11 +19,11 @@ func UpdateClusterRoleBindingFromYaml(k8sClient *kubernetes.Clientset, clusterRo
|
|||||||
|
|
||||||
func updateClusterRoleBinding(k8sClient *kubernetes.Clientset, crb interface{}) error {
|
func updateClusterRoleBinding(k8sClient *kubernetes.Clientset, crb interface{}) error {
|
||||||
clusterRoleBinding := crb.(rbacv1.ClusterRoleBinding)
|
clusterRoleBinding := crb.(rbacv1.ClusterRoleBinding)
|
||||||
if _, err := k8sClient.RbacV1().ClusterRoleBindings().Create(&clusterRoleBinding); err != nil {
|
if _, err := k8sClient.RbacV1().ClusterRoleBindings().Create(context.TODO(), &clusterRoleBinding, metav1.CreateOptions{}); err != nil {
|
||||||
if !apierrors.IsAlreadyExists(err) {
|
if !apierrors.IsAlreadyExists(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := k8sClient.RbacV1().ClusterRoleBindings().Update(&clusterRoleBinding); err != nil {
|
if _, err := k8sClient.RbacV1().ClusterRoleBindings().Update(context.TODO(), &clusterRoleBinding, metav1.UpdateOptions{}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,11 +41,11 @@ func UpdateClusterRoleFromYaml(k8sClient *kubernetes.Clientset, clusterRoleYaml
|
|||||||
|
|
||||||
func updateClusterRole(k8sClient *kubernetes.Clientset, cr interface{}) error {
|
func updateClusterRole(k8sClient *kubernetes.Clientset, cr interface{}) error {
|
||||||
clusterRole := cr.(rbacv1.ClusterRole)
|
clusterRole := cr.(rbacv1.ClusterRole)
|
||||||
if _, err := k8sClient.RbacV1().ClusterRoles().Create(&clusterRole); err != nil {
|
if _, err := k8sClient.RbacV1().ClusterRoles().Create(context.TODO(), &clusterRole, metav1.CreateOptions{}); err != nil {
|
||||||
if !apierrors.IsAlreadyExists(err) {
|
if !apierrors.IsAlreadyExists(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := k8sClient.RbacV1().ClusterRoles().Update(&clusterRole); err != nil {
|
if _, err := k8sClient.RbacV1().ClusterRoles().Update(context.TODO(), &clusterRole, metav1.UpdateOptions{}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,10 @@
|
|||||||
package k8s
|
package k8s
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
@@ -27,13 +28,13 @@ func UpdateConfigMap(k8sClient *kubernetes.Clientset, configYaml []byte, configM
|
|||||||
return updated, err
|
return updated, err
|
||||||
}
|
}
|
||||||
// the config map is not in k8s, I will create it and return updated=false
|
// the config map is not in k8s, I will create it and return updated=false
|
||||||
if _, err := k8sClient.CoreV1().ConfigMaps(metav1.NamespaceSystem).Create(cfgMap); err != nil {
|
if _, err := k8sClient.CoreV1().ConfigMaps(metav1.NamespaceSystem).Create(context.TODO(), cfgMap, metav1.CreateOptions{}); err != nil {
|
||||||
return updated, err
|
return updated, err
|
||||||
}
|
}
|
||||||
return updated, nil
|
return updated, nil
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(existingConfigMap.Data, cfgMap.Data) {
|
if !reflect.DeepEqual(existingConfigMap.Data, cfgMap.Data) {
|
||||||
if _, err := k8sClient.CoreV1().ConfigMaps(metav1.NamespaceSystem).Update(cfgMap); err != nil {
|
if _, err := k8sClient.CoreV1().ConfigMaps(metav1.NamespaceSystem).Update(context.TODO(), cfgMap, metav1.UpdateOptions{}); err != nil {
|
||||||
return updated, err
|
return updated, err
|
||||||
}
|
}
|
||||||
updated = true
|
updated = true
|
||||||
@@ -42,9 +43,9 @@ func UpdateConfigMap(k8sClient *kubernetes.Clientset, configYaml []byte, configM
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetConfigMap(k8sClient *kubernetes.Clientset, configMapName string) (*v1.ConfigMap, error) {
|
func GetConfigMap(k8sClient *kubernetes.Clientset, configMapName string) (*v1.ConfigMap, error) {
|
||||||
return k8sClient.CoreV1().ConfigMaps(metav1.NamespaceSystem).Get(configMapName, metav1.GetOptions{})
|
return k8sClient.CoreV1().ConfigMaps(metav1.NamespaceSystem).Get(context.TODO(), configMapName, metav1.GetOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteConfigMap(k8sClient *kubernetes.Clientset, configMapName string) error {
|
func DeleteConfigMap(k8sClient *kubernetes.Clientset, configMapName string) error {
|
||||||
return k8sClient.CoreV1().ConfigMaps(metav1.NamespaceSystem).Delete(configMapName, &metav1.DeleteOptions{})
|
return k8sClient.CoreV1().ConfigMaps(metav1.NamespaceSystem).Delete(context.TODO(), configMapName, metav1.DeleteOptions{})
|
||||||
}
|
}
|
||||||
|
13
k8s/job.go
13
k8s/job.go
@@ -1,9 +1,11 @@
|
|||||||
package k8s
|
package k8s
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"k8s.io/api/batch/v1"
|
v1 "k8s.io/api/batch/v1"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@@ -40,7 +42,7 @@ func ApplyK8sSystemJob(jobYaml, kubeConfigPath string, k8sWrapTransport transpor
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if _, err = k8sClient.BatchV1().Jobs(job.Namespace).Create(&job); err != nil {
|
if _, err = k8sClient.BatchV1().Jobs(job.Namespace).Create(context.TODO(), &job, metav1.CreateOptions{}); err != nil {
|
||||||
if apierrors.IsAlreadyExists(err) {
|
if apierrors.IsAlreadyExists(err) {
|
||||||
logrus.Debugf("[k8s] Job %s already exists..", job.Name)
|
logrus.Debugf("[k8s] Job %s already exists..", job.Name)
|
||||||
return nil
|
return nil
|
||||||
@@ -85,7 +87,7 @@ func ensureJobCompleted(k8sClient *kubernetes.Clientset, j interface{}) error {
|
|||||||
|
|
||||||
func ensureJobDeleted(k8sClient *kubernetes.Clientset, j interface{}) error {
|
func ensureJobDeleted(k8sClient *kubernetes.Clientset, j interface{}) error {
|
||||||
job := j.(v1.Job)
|
job := j.(v1.Job)
|
||||||
_, err := k8sClient.BatchV1().Jobs(job.Namespace).Get(job.Name, metav1.GetOptions{})
|
_, err := k8sClient.BatchV1().Jobs(job.Namespace).Get(context.TODO(), job.Name, metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if apierrors.IsNotFound(err) {
|
if apierrors.IsNotFound(err) {
|
||||||
// this is the "true" return of the function
|
// this is the "true" return of the function
|
||||||
@@ -99,14 +101,15 @@ func ensureJobDeleted(k8sClient *kubernetes.Clientset, j interface{}) error {
|
|||||||
func deleteK8sJob(k8sClient *kubernetes.Clientset, name, namespace string) error {
|
func deleteK8sJob(k8sClient *kubernetes.Clientset, name, namespace string) error {
|
||||||
deletePolicy := metav1.DeletePropagationForeground
|
deletePolicy := metav1.DeletePropagationForeground
|
||||||
return k8sClient.BatchV1().Jobs(namespace).Delete(
|
return k8sClient.BatchV1().Jobs(namespace).Delete(
|
||||||
|
context.TODO(),
|
||||||
name,
|
name,
|
||||||
&metav1.DeleteOptions{
|
metav1.DeleteOptions{
|
||||||
PropagationPolicy: &deletePolicy,
|
PropagationPolicy: &deletePolicy,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func getK8sJob(k8sClient *kubernetes.Clientset, name, namespace string) (*v1.Job, error) {
|
func getK8sJob(k8sClient *kubernetes.Clientset, name, namespace string) (*v1.Job, error) {
|
||||||
return k8sClient.BatchV1().Jobs(namespace).Get(name, metav1.GetOptions{})
|
return k8sClient.BatchV1().Jobs(namespace).Get(context.TODO(), name, metav1.GetOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetK8sJobStatus(k8sClient *kubernetes.Clientset, name, namespace string) (JobStatus, error) {
|
func GetK8sJobStatus(k8sClient *kubernetes.Clientset, name, namespace string) (JobStatus, error) {
|
||||||
|
11
k8s/node.go
11
k8s/node.go
@@ -1,12 +1,13 @@
|
|||||||
package k8s
|
package k8s
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
@@ -31,11 +32,11 @@ func DeleteNode(k8sClient *kubernetes.Clientset, nodeName, cloudProvider string)
|
|||||||
}
|
}
|
||||||
nodeName = node.Name
|
nodeName = node.Name
|
||||||
}
|
}
|
||||||
return k8sClient.CoreV1().Nodes().Delete(nodeName, &metav1.DeleteOptions{})
|
return k8sClient.CoreV1().Nodes().Delete(context.TODO(), nodeName, metav1.DeleteOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetNodeList(k8sClient *kubernetes.Clientset) (*v1.NodeList, error) {
|
func GetNodeList(k8sClient *kubernetes.Clientset) (*v1.NodeList, error) {
|
||||||
return k8sClient.CoreV1().Nodes().List(metav1.ListOptions{})
|
return k8sClient.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetNode(k8sClient *kubernetes.Clientset, nodeName string) (*v1.Node, error) {
|
func GetNode(k8sClient *kubernetes.Clientset, nodeName string) (*v1.Node, error) {
|
||||||
@@ -77,7 +78,7 @@ func CordonUncordon(k8sClient *kubernetes.Clientset, nodeName string, cordoned b
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
node.Spec.Unschedulable = cordoned
|
node.Spec.Unschedulable = cordoned
|
||||||
_, err = k8sClient.CoreV1().Nodes().Update(node)
|
_, err = k8sClient.CoreV1().Nodes().Update(context.TODO(), node, metav1.UpdateOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("Error setting cordoned state for node %s: %v", nodeName, err)
|
logrus.Debugf("Error setting cordoned state for node %s: %v", nodeName, err)
|
||||||
time.Sleep(time.Second * RetryInterval)
|
time.Sleep(time.Second * RetryInterval)
|
||||||
@@ -125,7 +126,7 @@ func RemoveTaintFromNodeByKey(k8sClient *kubernetes.Clientset, nodeName, taintKe
|
|||||||
if !foundTaint {
|
if !foundTaint {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
_, err = k8sClient.CoreV1().Nodes().Update(node)
|
_, err = k8sClient.CoreV1().Nodes().Update(context.TODO(), node, metav1.UpdateOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("Error updating node [%s] with new set of taints: %v", node.Name, err)
|
logrus.Debugf("Error updating node [%s] with new set of taints: %v", node.Name, err)
|
||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
package k8s
|
package k8s
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@@ -9,7 +11,7 @@ import (
|
|||||||
|
|
||||||
func DeletePods(k8sClient *kubernetes.Clientset, podList *v1.PodList) error {
|
func DeletePods(k8sClient *kubernetes.Clientset, podList *v1.PodList) error {
|
||||||
for _, pod := range podList.Items {
|
for _, pod := range podList.Items {
|
||||||
if err := k8sClient.CoreV1().Pods(pod.Namespace).Delete(pod.Name, &metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) {
|
if err := k8sClient.CoreV1().Pods(pod.Namespace).Delete(context.TODO(), pod.Name, metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,7 +19,7 @@ func DeletePods(k8sClient *kubernetes.Clientset, podList *v1.PodList) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ListPodsByLabel(k8sClient *kubernetes.Clientset, label string) (*v1.PodList, error) {
|
func ListPodsByLabel(k8sClient *kubernetes.Clientset, label string) (*v1.PodList, error) {
|
||||||
pods, err := k8sClient.CoreV1().Pods("").List(metav1.ListOptions{LabelSelector: label})
|
pods, err := k8sClient.CoreV1().Pods("").List(context.TODO(), metav1.ListOptions{LabelSelector: label})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,11 @@
|
|||||||
package k8s
|
package k8s
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"k8s.io/api/policy/v1beta1"
|
"k8s.io/api/policy/v1beta1"
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,11 +19,11 @@ func UpdatePodSecurityPolicyFromYaml(k8sClient *kubernetes.Clientset, pspYaml st
|
|||||||
|
|
||||||
func updatePodSecurityPolicy(k8sClient *kubernetes.Clientset, p interface{}) error {
|
func updatePodSecurityPolicy(k8sClient *kubernetes.Clientset, p interface{}) error {
|
||||||
psp := p.(v1beta1.PodSecurityPolicy)
|
psp := p.(v1beta1.PodSecurityPolicy)
|
||||||
if _, err := k8sClient.PolicyV1beta1().PodSecurityPolicies().Create(&psp); err != nil {
|
if _, err := k8sClient.PolicyV1beta1().PodSecurityPolicies().Create(context.TODO(), &psp, metav1.CreateOptions{}); err != nil {
|
||||||
if !apierrors.IsAlreadyExists(err) {
|
if !apierrors.IsAlreadyExists(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := k8sClient.PolicyV1beta1().PodSecurityPolicies().Update(&psp); err != nil {
|
if _, err := k8sClient.PolicyV1beta1().PodSecurityPolicies().Update(context.TODO(), &psp, metav1.UpdateOptions{}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
11
k8s/role.go
11
k8s/role.go
@@ -1,8 +1,11 @@
|
|||||||
package k8s
|
package k8s
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
rbacv1 "k8s.io/api/rbac/v1"
|
rbacv1 "k8s.io/api/rbac/v1"
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,11 +20,11 @@ func UpdateRoleBindingFromYaml(k8sClient *kubernetes.Clientset, roleBindingYaml,
|
|||||||
|
|
||||||
func updateRoleBinding(k8sClient *kubernetes.Clientset, rb interface{}) error {
|
func updateRoleBinding(k8sClient *kubernetes.Clientset, rb interface{}) error {
|
||||||
roleBinding := rb.(rbacv1.RoleBinding)
|
roleBinding := rb.(rbacv1.RoleBinding)
|
||||||
if _, err := k8sClient.RbacV1().RoleBindings(roleBinding.Namespace).Create(&roleBinding); err != nil {
|
if _, err := k8sClient.RbacV1().RoleBindings(roleBinding.Namespace).Create(context.TODO(), &roleBinding, metav1.CreateOptions{}); err != nil {
|
||||||
if !apierrors.IsAlreadyExists(err) {
|
if !apierrors.IsAlreadyExists(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := k8sClient.RbacV1().RoleBindings(roleBinding.Namespace).Update(&roleBinding); err != nil {
|
if _, err := k8sClient.RbacV1().RoleBindings(roleBinding.Namespace).Update(context.TODO(), &roleBinding, metav1.UpdateOptions{}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,11 +42,11 @@ func UpdateRoleFromYaml(k8sClient *kubernetes.Clientset, roleYaml, namespace str
|
|||||||
|
|
||||||
func updateRole(k8sClient *kubernetes.Clientset, r interface{}) error {
|
func updateRole(k8sClient *kubernetes.Clientset, r interface{}) error {
|
||||||
role := r.(rbacv1.Role)
|
role := r.(rbacv1.Role)
|
||||||
if _, err := k8sClient.RbacV1().Roles(role.Namespace).Create(&role); err != nil {
|
if _, err := k8sClient.RbacV1().Roles(role.Namespace).Create(context.TODO(), &role, metav1.CreateOptions{}); err != nil {
|
||||||
if !apierrors.IsAlreadyExists(err) {
|
if !apierrors.IsAlreadyExists(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := k8sClient.RbacV1().Roles(role.Namespace).Update(&role); err != nil {
|
if _, err := k8sClient.RbacV1().Roles(role.Namespace).Update(context.TODO(), &role, metav1.UpdateOptions{}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
package k8s
|
package k8s
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"k8s.io/api/core/v1"
|
"context"
|
||||||
|
|
||||||
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
)
|
)
|
||||||
@@ -11,15 +13,15 @@ func GetSystemSecret(k8sClient *kubernetes.Clientset, secretName string) (*v1.Se
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetSecret(k8sClient *kubernetes.Clientset, secretName, namespace string) (*v1.Secret, error) {
|
func GetSecret(k8sClient *kubernetes.Clientset, secretName, namespace string) (*v1.Secret, error) {
|
||||||
return k8sClient.CoreV1().Secrets(namespace).Get(secretName, metav1.GetOptions{})
|
return k8sClient.CoreV1().Secrets(namespace).Get(context.TODO(), secretName, metav1.GetOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetSecretsList(k8sClient *kubernetes.Clientset, namespace string) (*v1.SecretList, error) {
|
func GetSecretsList(k8sClient *kubernetes.Clientset, namespace string) (*v1.SecretList, error) {
|
||||||
return k8sClient.CoreV1().Secrets("").List(metav1.ListOptions{})
|
return k8sClient.CoreV1().Secrets("").List(context.TODO(), metav1.ListOptions{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateSecret(k8sClient *kubernetes.Clientset, secret *v1.Secret) error {
|
func UpdateSecret(k8sClient *kubernetes.Clientset, secret *v1.Secret) error {
|
||||||
var err error
|
var err error
|
||||||
_, err = k8sClient.CoreV1().Secrets(secret.Namespace).Update(secret)
|
_, err = k8sClient.CoreV1().Secrets(secret.Namespace).Update(context.TODO(), secret, metav1.UpdateOptions{})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
package k8s
|
package k8s
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"k8s.io/api/core/v1"
|
"context"
|
||||||
|
|
||||||
|
v1 "k8s.io/api/core/v1"
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
@@ -18,11 +20,11 @@ func UpdateServiceAccountFromYaml(k8sClient *kubernetes.Clientset, serviceAccoun
|
|||||||
|
|
||||||
func updateServiceAccount(k8sClient *kubernetes.Clientset, s interface{}) error {
|
func updateServiceAccount(k8sClient *kubernetes.Clientset, s interface{}) error {
|
||||||
serviceAccount := s.(v1.ServiceAccount)
|
serviceAccount := s.(v1.ServiceAccount)
|
||||||
if _, err := k8sClient.CoreV1().ServiceAccounts(metav1.NamespaceSystem).Create(&serviceAccount); err != nil {
|
if _, err := k8sClient.CoreV1().ServiceAccounts(metav1.NamespaceSystem).Create(context.TODO(), &serviceAccount, metav1.CreateOptions{}); err != nil {
|
||||||
if !apierrors.IsAlreadyExists(err) {
|
if !apierrors.IsAlreadyExists(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := k8sClient.CoreV1().ServiceAccounts(metav1.NamespaceSystem).Update(&serviceAccount); err != nil {
|
if _, err := k8sClient.CoreV1().ServiceAccounts(metav1.NamespaceSystem).Update(context.TODO(), &serviceAccount, metav1.UpdateOptions{}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user