From 2677c1d5941cf8b9f8d8478fe1833f9b983527ca Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Tue, 26 Dec 2017 17:42:24 -0500 Subject: [PATCH] Remove TryPatch methods (#254) --- client/typed/stash/v1alpha1/util/recovery.go | 21 ----- client/typed/stash/v1alpha1/util/restic.go | 21 ----- glide.lock | 4 +- .../appscode/kutil/apps/v1beta1/deployment.go | 21 ----- .../kutil/apps/v1beta1/statefulset.go | 50 +++++++----- .../appscode/kutil/batch/v1beta1/cronjob.go | 21 ----- .../appscode/kutil/core/v1/configmap.go | 21 ----- .../github.com/appscode/kutil/core/v1/node.go | 21 ----- .../github.com/appscode/kutil/core/v1/pod.go | 76 ++++++++++++++----- .../github.com/appscode/kutil/core/v1/rc.go | 21 ----- .../appscode/kutil/core/v1/secret.go | 30 +++----- .../appscode/kutil/core/v1/service.go | 24 +----- .../appscode/kutil/core/v1/serviceaccount.go | 21 ----- .../kutil/extensions/v1beta1/daemonset.go | 21 ----- .../kutil/extensions/v1beta1/deployment.go | 21 ----- .../kutil/extensions/v1beta1/replicaset.go | 21 ----- .../appscode/kutil/meta/annotations.go | 16 ++++ .../kutil/rbac/v1beta1/clusterrole.go | 21 ----- .../kutil/rbac/v1beta1/clusterrolebinding.go | 21 ----- .../appscode/kutil/rbac/v1beta1/role.go | 21 ----- .../kutil/rbac/v1beta1/rolebinding.go | 21 ----- 21 files changed, 114 insertions(+), 401 deletions(-) diff --git a/client/typed/stash/v1alpha1/util/recovery.go b/client/typed/stash/v1alpha1/util/recovery.go index 56c46b377..473e99438 100644 --- a/client/typed/stash/v1alpha1/util/recovery.go +++ b/client/typed/stash/v1alpha1/util/recovery.go @@ -58,27 +58,6 @@ func PatchRecovery(c cs.StashV1alpha1Interface, cur *api.Recovery, transform fun return out, kutil.VerbPatched, err } -func TryPatchRecovery(c cs.StashV1alpha1Interface, meta metav1.ObjectMeta, transform func(*api.Recovery) *api.Recovery) (result *api.Recovery, err error) { - attempt := 0 - err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { - attempt++ - cur, e2 := c.Recoveries(meta.Namespace).Get(meta.Name, metav1.GetOptions{}) - if kerr.IsNotFound(e2) { - return false, e2 - } else if e2 == nil { - result, _, e2 = PatchRecovery(c, cur, transform) - return e2 == nil, nil - } - glog.Errorf("Attempt %d failed to patch Recovery %s/%s due to %v.", attempt, cur.Namespace, cur.Name, e2) - return false, nil - }) - - if err != nil { - err = fmt.Errorf("failed to patch Recovery %s/%s after %d attempts due to %v", meta.Namespace, meta.Name, attempt, err) - } - return -} - func TryUpdateRecovery(c cs.StashV1alpha1Interface, meta metav1.ObjectMeta, transform func(*api.Recovery) *api.Recovery) (result *api.Recovery, err error) { attempt := 0 err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { diff --git a/client/typed/stash/v1alpha1/util/restic.go b/client/typed/stash/v1alpha1/util/restic.go index 3b46a9ff1..c8e273a25 100644 --- a/client/typed/stash/v1alpha1/util/restic.go +++ b/client/typed/stash/v1alpha1/util/restic.go @@ -56,27 +56,6 @@ func PatchRestic(c cs.StashV1alpha1Interface, cur *api.Restic, transform func(*a return out, kutil.VerbPatched, err } -func TryPatchRestic(c cs.StashV1alpha1Interface, meta metav1.ObjectMeta, transform func(*api.Restic) *api.Restic) (result *api.Restic, err error) { - attempt := 0 - err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { - attempt++ - cur, e2 := c.Restics(meta.Namespace).Get(meta.Name, metav1.GetOptions{}) - if kerr.IsNotFound(e2) { - return false, e2 - } else if e2 == nil { - result, _, e2 = PatchRestic(c, cur, transform) - return e2 == nil, nil - } - glog.Errorf("Attempt %d failed to patch Restic %s/%s due to %v.", attempt, cur.Namespace, cur.Name, e2) - return false, nil - }) - - if err != nil { - err = fmt.Errorf("failed to patch Restic %s/%s after %d attempts due to %v", meta.Namespace, meta.Name, attempt, err) - } - return -} - func TryUpdateRestic(c cs.StashV1alpha1Interface, meta metav1.ObjectMeta, transform func(*api.Restic) *api.Restic) (result *api.Restic, err error) { attempt := 0 err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { diff --git a/glide.lock b/glide.lock index 8f25c7182..b5854ccf2 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ hash: 6f32b235515f97ee7b2713b3134e3c6843d84cd8d58869d83193c4a99b4e3a2a -updated: 2017-12-22T03:47:06.412356791-05:00 +updated: 2017-12-26T17:36:59.654755674-05:00 imports: - name: github.com/appscode/go version: f08cee5a2aa53a1ab6d30e4ae11e381d1b265f81 @@ -15,7 +15,7 @@ imports: - types - version - name: github.com/appscode/kutil - version: 04124fd21c654188d7a11908d8c8af994a4cccef + version: 27239d39c245b5237d1035f2873db9c2d895c34b subpackages: - apiextensions/v1beta1 - apps/v1beta1 diff --git a/vendor/github.com/appscode/kutil/apps/v1beta1/deployment.go b/vendor/github.com/appscode/kutil/apps/v1beta1/deployment.go index ec59b1328..6841dcbbf 100644 --- a/vendor/github.com/appscode/kutil/apps/v1beta1/deployment.go +++ b/vendor/github.com/appscode/kutil/apps/v1beta1/deployment.go @@ -57,27 +57,6 @@ func PatchDeployment(c kubernetes.Interface, cur *apps.Deployment, transform fun return out, kutil.VerbPatched, err } -func TryPatchDeployment(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*apps.Deployment) *apps.Deployment) (result *apps.Deployment, err error) { - attempt := 0 - err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { - attempt++ - cur, e2 := c.AppsV1beta1().Deployments(meta.Namespace).Get(meta.Name, metav1.GetOptions{}) - if kerr.IsNotFound(e2) { - return false, e2 - } else if e2 == nil { - result, _, e2 = PatchDeployment(c, cur, transform) - return e2 == nil, nil - } - glog.Errorf("Attempt %d failed to patch Deployment %s/%s due to %v.", attempt, cur.Namespace, cur.Name, e2) - return false, nil - }) - - if err != nil { - err = fmt.Errorf("failed to patch Deployment %s/%s after %d attempts due to %v", meta.Namespace, meta.Name, attempt, err) - } - return -} - func TryUpdateDeployment(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*apps.Deployment) *apps.Deployment) (result *apps.Deployment, err error) { attempt := 0 err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { diff --git a/vendor/github.com/appscode/kutil/apps/v1beta1/statefulset.go b/vendor/github.com/appscode/kutil/apps/v1beta1/statefulset.go index 5a119067d..96c27b7f5 100644 --- a/vendor/github.com/appscode/kutil/apps/v1beta1/statefulset.go +++ b/vendor/github.com/appscode/kutil/apps/v1beta1/statefulset.go @@ -5,7 +5,9 @@ import ( "fmt" . "github.com/appscode/go/types" + atypes "github.com/appscode/go/types" "github.com/appscode/kutil" + core_util "github.com/appscode/kutil/core/v1" "github.com/golang/glog" apps "k8s.io/api/apps/v1beta1" kerr "k8s.io/apimachinery/pkg/api/errors" @@ -57,27 +59,6 @@ func PatchStatefulSet(c kubernetes.Interface, cur *apps.StatefulSet, transform f return out, kutil.VerbPatched, err } -func TryPatchStatefulSet(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*apps.StatefulSet) *apps.StatefulSet) (result *apps.StatefulSet, err error) { - attempt := 0 - err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { - attempt++ - cur, e2 := c.AppsV1beta1().StatefulSets(meta.Namespace).Get(meta.Name, metav1.GetOptions{}) - if kerr.IsNotFound(e2) { - return false, e2 - } else if e2 == nil { - result, _, e2 = PatchStatefulSet(c, cur, transform) - return e2 == nil, nil - } - glog.Errorf("Attempt %d failed to patch StatefulSet %s/%s due to %v.", attempt, cur.Namespace, cur.Name, e2) - return false, nil - }) - - if err != nil { - err = fmt.Errorf("failed to patch StatefulSet %s/%s after %d attempts due to %v", meta.Namespace, meta.Name, attempt, err) - } - return -} - func TryUpdateStatefulSet(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*apps.StatefulSet) *apps.StatefulSet) (result *apps.StatefulSet, err error) { attempt := 0 err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { @@ -107,3 +88,30 @@ func WaitUntilStatefulSetReady(kubeClient kubernetes.Interface, meta metav1.Obje return false, nil }) } + +func DeleteStatefulSet(kubeClient kubernetes.Interface, meta metav1.ObjectMeta) error { + statefulSet, err := kubeClient.AppsV1beta1().StatefulSets(meta.Namespace).Get(meta.Name, metav1.GetOptions{}) + if err != nil { + if kerr.IsNotFound(err) { + return nil + } else { + return err + } + } + + // Update StatefulSet + _, _, err = PatchStatefulSet(kubeClient, statefulSet, func(in *apps.StatefulSet) *apps.StatefulSet { + in.Spec.Replicas = atypes.Int32P(0) + return in + }) + if err != nil { + return err + } + + err = core_util.WaitUntilPodDeletedBySelector(kubeClient, statefulSet.Namespace, statefulSet.Spec.Selector) + if err != nil { + return err + } + + return kubeClient.AppsV1beta1().StatefulSets(statefulSet.Namespace).Delete(statefulSet.Name, nil) +} diff --git a/vendor/github.com/appscode/kutil/batch/v1beta1/cronjob.go b/vendor/github.com/appscode/kutil/batch/v1beta1/cronjob.go index 125030c8d..0a200a8d2 100644 --- a/vendor/github.com/appscode/kutil/batch/v1beta1/cronjob.go +++ b/vendor/github.com/appscode/kutil/batch/v1beta1/cronjob.go @@ -56,27 +56,6 @@ func PatchCronJob(c kubernetes.Interface, cur *batch.CronJob, transform func(*ba return out, kutil.VerbPatched, err } -func TryPatchCronJob(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*batch.CronJob) *batch.CronJob) (result *batch.CronJob, err error) { - attempt := 0 - err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { - attempt++ - cur, e2 := c.BatchV1beta1().CronJobs(meta.Namespace).Get(meta.Name, metav1.GetOptions{}) - if kerr.IsNotFound(e2) { - return false, e2 - } else if e2 == nil { - result, _, e2 = PatchCronJob(c, cur, transform) - return e2 == nil, nil - } - glog.Errorf("Attempt %d failed to patch CronJob %s/%s due to %v.", attempt, cur.Namespace, cur.Name, e2) - return false, nil - }) - - if err != nil { - err = fmt.Errorf("failed to patch CronJob %s/%s after %d attempts due to %v", meta.Namespace, meta.Name, attempt, err) - } - return -} - func TryUpdateCronJob(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*batch.CronJob) *batch.CronJob) (result *batch.CronJob, err error) { attempt := 0 err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { diff --git a/vendor/github.com/appscode/kutil/core/v1/configmap.go b/vendor/github.com/appscode/kutil/core/v1/configmap.go index f9ec24943..1142a43bc 100644 --- a/vendor/github.com/appscode/kutil/core/v1/configmap.go +++ b/vendor/github.com/appscode/kutil/core/v1/configmap.go @@ -56,27 +56,6 @@ func PatchConfigMap(c kubernetes.Interface, cur *core.ConfigMap, transform func( return out, kutil.VerbPatched, err } -func TryPatchConfigMap(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*core.ConfigMap) *core.ConfigMap) (result *core.ConfigMap, err error) { - attempt := 0 - err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { - attempt++ - cur, e2 := c.CoreV1().ConfigMaps(meta.Namespace).Get(meta.Name, metav1.GetOptions{}) - if kerr.IsNotFound(e2) { - return false, e2 - } else if e2 == nil { - result, _, e2 = PatchConfigMap(c, cur, transform) - return e2 == nil, nil - } - glog.Errorf("Attempt %d failed to patch ConfigMap %s/%s due to %v.", attempt, cur.Namespace, cur.Name, e2) - return false, nil - }) - - if err != nil { - err = fmt.Errorf("failed to patch ConfigMap %s/%s after %d attempts due to %v", meta.Namespace, meta.Name, attempt, err) - } - return -} - func TryUpdateConfigMap(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*core.ConfigMap) *core.ConfigMap) (result *core.ConfigMap, err error) { attempt := 0 err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { diff --git a/vendor/github.com/appscode/kutil/core/v1/node.go b/vendor/github.com/appscode/kutil/core/v1/node.go index d062ad6f3..594b80359 100644 --- a/vendor/github.com/appscode/kutil/core/v1/node.go +++ b/vendor/github.com/appscode/kutil/core/v1/node.go @@ -56,27 +56,6 @@ func PatchNode(c kubernetes.Interface, cur *core.Node, transform func(*core.Node return out, kutil.VerbPatched, err } -func TryPatchNode(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*core.Node) *core.Node) (result *core.Node, err error) { - attempt := 0 - err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { - attempt++ - cur, e2 := c.CoreV1().Nodes().Get(meta.Name, metav1.GetOptions{}) - if kerr.IsNotFound(e2) { - return false, e2 - } else if e2 == nil { - result, _, e2 = PatchNode(c, cur, transform) - return e2 == nil, nil - } - glog.Errorf("Attempt %d failed to patch Node %s due to %v.", attempt, cur.Name, e2) - return false, nil - }) - - if err != nil { - err = fmt.Errorf("failed to patch Node %s after %d attempts due to %v", meta.Name, attempt, err) - } - return -} - func TryUpdateNode(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*core.Node) *core.Node) (result *core.Node, err error) { attempt := 0 err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { diff --git a/vendor/github.com/appscode/kutil/core/v1/pod.go b/vendor/github.com/appscode/kutil/core/v1/pod.go index ed1d79092..3b1054fe2 100644 --- a/vendor/github.com/appscode/kutil/core/v1/pod.go +++ b/vendor/github.com/appscode/kutil/core/v1/pod.go @@ -57,27 +57,6 @@ func PatchPod(c kubernetes.Interface, cur *core.Pod, transform func(*core.Pod) * return out, kutil.VerbPatched, err } -func TryPatchPod(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*core.Pod) *core.Pod) (result *core.Pod, err error) { - attempt := 0 - err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { - attempt++ - cur, e2 := c.CoreV1().Pods(meta.Namespace).Get(meta.Name, metav1.GetOptions{}) - if kerr.IsNotFound(e2) { - return false, e2 - } else if e2 == nil { - result, _, e2 = PatchPod(c, cur, transform) - return e2 == nil, nil - } - glog.Errorf("Attempt %d failed to patch Pod %s/%s due to %v.", attempt, cur.Namespace, cur.Name, e2) - return false, nil - }) - - if err != nil { - err = fmt.Errorf("failed to patch Pod %s/%s after %d attempts due to %v", meta.Namespace, meta.Name, attempt, err) - } - return -} - func TryUpdatePod(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*core.Pod) *core.Pod) (result *core.Pod, err error) { attempt := 0 err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { @@ -127,3 +106,58 @@ func RestartPods(kubeClient kubernetes.Interface, namespace string, selector *me LabelSelector: r.String(), }) } + +func WaitUntilPodRunning(kubeClient kubernetes.Interface, meta metav1.ObjectMeta) error { + return wait.PollImmediate(kutil.RetryInterval, kutil.ReadinessTimeout, func() (bool, error) { + if pod, err := kubeClient.CoreV1().Pods(meta.Namespace).Get(meta.Name, metav1.GetOptions{}); err == nil { + runningAndReady, _ := PodRunningAndReady(*pod) + return runningAndReady, nil + } + return false, nil + }) +} + +func WaitUntilPodRunningBySelector(kubeClient kubernetes.Interface, namespace string, selector *metav1.LabelSelector, count int) error { + r, err := metav1.LabelSelectorAsSelector(selector) + if err != nil { + return err + } + + return wait.PollImmediate(kutil.RetryInterval, kutil.ReadinessTimeout, func() (bool, error) { + podList, err := kubeClient.CoreV1().Pods(namespace).List(metav1.ListOptions{ + LabelSelector: r.String(), + }) + if err != nil { + return false, nil + } + + if len(podList.Items) != count { + return false, nil + } + + for _, pod := range podList.Items { + runningAndReady, _ := PodRunningAndReady(pod) + if !runningAndReady { + return false, nil + } + } + return true, nil + }) +} + +func WaitUntilPodDeletedBySelector(kubeClient kubernetes.Interface, namespace string, selector *metav1.LabelSelector) error { + r, err := metav1.LabelSelectorAsSelector(selector) + if err != nil { + return err + } + + return wait.PollImmediate(kutil.RetryInterval, kutil.ReadinessTimeout, func() (bool, error) { + podList, err := kubeClient.CoreV1().Pods(namespace).List(metav1.ListOptions{ + LabelSelector: r.String(), + }) + if err != nil { + return false, nil + } + return len(podList.Items) == 0, nil + }) +} diff --git a/vendor/github.com/appscode/kutil/core/v1/rc.go b/vendor/github.com/appscode/kutil/core/v1/rc.go index 82028a3e6..07de7170e 100644 --- a/vendor/github.com/appscode/kutil/core/v1/rc.go +++ b/vendor/github.com/appscode/kutil/core/v1/rc.go @@ -57,27 +57,6 @@ func PatchRC(c kubernetes.Interface, cur *core.ReplicationController, transform return out, kutil.VerbPatched, err } -func TryPatchRC(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*core.ReplicationController) *core.ReplicationController) (result *core.ReplicationController, err error) { - attempt := 0 - err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { - attempt++ - cur, e2 := c.CoreV1().ReplicationControllers(meta.Namespace).Get(meta.Name, metav1.GetOptions{}) - if kerr.IsNotFound(e2) { - return false, e2 - } else if e2 == nil { - result, _, e2 = PatchRC(c, cur, transform) - return e2 == nil, nil - } - glog.Errorf("Attempt %d failed to patch ReplicationController %s/%s due to %v.", attempt, cur.Namespace, cur.Name, e2) - return false, nil - }) - - if err != nil { - err = fmt.Errorf("failed to patch ReplicationController %s/%s after %d attempts due to %v", meta.Namespace, meta.Name, attempt, err) - } - return -} - func TryUpdateRC(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*core.ReplicationController) *core.ReplicationController) (result *core.ReplicationController, err error) { attempt := 0 err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { diff --git a/vendor/github.com/appscode/kutil/core/v1/secret.go b/vendor/github.com/appscode/kutil/core/v1/secret.go index 064bea1f0..ffeee9155 100644 --- a/vendor/github.com/appscode/kutil/core/v1/secret.go +++ b/vendor/github.com/appscode/kutil/core/v1/secret.go @@ -56,27 +56,6 @@ func PatchSecret(c kubernetes.Interface, cur *core.Secret, transform func(*core. return out, kutil.VerbPatched, err } -func TryPatchSecret(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*core.Secret) *core.Secret) (result *core.Secret, err error) { - attempt := 0 - err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { - attempt++ - cur, e2 := c.CoreV1().Secrets(meta.Namespace).Get(meta.Name, metav1.GetOptions{}) - if kerr.IsNotFound(e2) { - return false, e2 - } else if e2 == nil { - result, _, e2 = PatchSecret(c, cur, transform) - return e2 == nil, nil - } - glog.Errorf("Attempt %d failed to patch Secret %s/%s due to %v.", attempt, cur.Namespace, cur.Name, e2) - return false, nil - }) - - if err != nil { - err = fmt.Errorf("failed to patch Secret %s/%s after %d attempts due to %v", meta.Namespace, meta.Name, attempt, err) - } - return -} - func TryUpdateSecret(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*core.Secret) *core.Secret) (result *core.Secret, err error) { attempt := 0 err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { @@ -97,3 +76,12 @@ func TryUpdateSecret(c kubernetes.Interface, meta metav1.ObjectMeta, transform f } return } + +func ObfuscateSecret(in core.Secret) *core.Secret { + data := make(map[string][]byte) + for k := range in.Data { + data[k] = []byte("-") + } + in.Data = data + return &in +} diff --git a/vendor/github.com/appscode/kutil/core/v1/service.go b/vendor/github.com/appscode/kutil/core/v1/service.go index 884f3a877..6a7cdfefe 100644 --- a/vendor/github.com/appscode/kutil/core/v1/service.go +++ b/vendor/github.com/appscode/kutil/core/v1/service.go @@ -56,27 +56,6 @@ func PatchService(c kubernetes.Interface, cur *core.Service, transform func(*cor return out, kutil.VerbPatched, err } -func TryPatchService(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*core.Service) *core.Service) (result *core.Service, err error) { - attempt := 0 - err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { - attempt++ - cur, e2 := c.CoreV1().Services(meta.Namespace).Get(meta.Name, metav1.GetOptions{}) - if kerr.IsNotFound(e2) { - return false, e2 - } else if e2 == nil { - result, _, e2 = PatchService(c, cur, transform) - return e2 == nil, nil - } - glog.Errorf("Attempt %d failed to patch Service %s/%s due to %v.", attempt, cur.Namespace, cur.Name, e2) - return false, nil - }) - - if err != nil { - err = fmt.Errorf("failed to patch Service %s/%s after %d attempts due to %v", meta.Namespace, meta.Name, attempt, err) - } - return -} - func TryUpdateService(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*core.Service) *core.Service) (result *core.Service, err error) { attempt := 0 err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { @@ -119,6 +98,9 @@ func MergeServicePorts(cur, desired []core.ServicePort) []core.ServicePort { if dp.NodePort == 0 { dp.NodePort = cp.NodePort // avoid reassigning port } + if dp.Protocol == "" { + dp.Protocol = cp.Protocol + } desired[i] = dp } return desired diff --git a/vendor/github.com/appscode/kutil/core/v1/serviceaccount.go b/vendor/github.com/appscode/kutil/core/v1/serviceaccount.go index 5c9686490..1a64b94d1 100644 --- a/vendor/github.com/appscode/kutil/core/v1/serviceaccount.go +++ b/vendor/github.com/appscode/kutil/core/v1/serviceaccount.go @@ -56,27 +56,6 @@ func PatchServiceAccount(c kubernetes.Interface, cur *core.ServiceAccount, trans return out, kutil.VerbPatched, err } -func TryPatchServiceAccount(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*core.ServiceAccount) *core.ServiceAccount) (result *core.ServiceAccount, err error) { - attempt := 0 - err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { - attempt++ - cur, e2 := c.CoreV1().ServiceAccounts(meta.Namespace).Get(meta.Name, metav1.GetOptions{}) - if kerr.IsNotFound(e2) { - return false, e2 - } else if e2 == nil { - result, _, e2 = PatchServiceAccount(c, cur, transform) - return e2 == nil, nil - } - glog.Errorf("Attempt %d failed to patch ServiceAccount %s/%s due to %v.", attempt, cur.Namespace, cur.Name, e2) - return false, nil - }) - - if err != nil { - err = fmt.Errorf("failed to patch ServiceAccount %s/%s after %d attempts due to %v", meta.Namespace, meta.Name, attempt, err) - } - return -} - func TryUpdateServiceAccount(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*core.ServiceAccount) *core.ServiceAccount) (result *core.ServiceAccount, err error) { attempt := 0 err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { diff --git a/vendor/github.com/appscode/kutil/extensions/v1beta1/daemonset.go b/vendor/github.com/appscode/kutil/extensions/v1beta1/daemonset.go index 8c5cc7785..38919c42b 100644 --- a/vendor/github.com/appscode/kutil/extensions/v1beta1/daemonset.go +++ b/vendor/github.com/appscode/kutil/extensions/v1beta1/daemonset.go @@ -62,27 +62,6 @@ func PatchDaemonSet(c kubernetes.Interface, cur *extensions.DaemonSet, transform return out, kutil.VerbPatched, err } -func TryPatchDaemonSet(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*extensions.DaemonSet) *extensions.DaemonSet) (result *extensions.DaemonSet, err error) { - attempt := 0 - err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { - attempt++ - cur, e2 := c.ExtensionsV1beta1().DaemonSets(meta.Namespace).Get(meta.Name, metav1.GetOptions{}) - if kerr.IsNotFound(e2) { - return false, e2 - } else if e2 == nil { - result, _, e2 = PatchDaemonSet(c, cur, transform) - return e2 == nil, nil - } - glog.Errorf("Attempt %d failed to patch DaemonSet %s/%s due to %v.", attempt, cur.Namespace, cur.Name, e2) - return false, nil - }) - - if err != nil { - err = fmt.Errorf("failed to patch DaemonSet %s/%s after %d attempts due to %v", meta.Namespace, meta.Name, attempt, err) - } - return -} - func TryUpdateDaemonSet(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*extensions.DaemonSet) *extensions.DaemonSet) (result *extensions.DaemonSet, err error) { attempt := 0 err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { diff --git a/vendor/github.com/appscode/kutil/extensions/v1beta1/deployment.go b/vendor/github.com/appscode/kutil/extensions/v1beta1/deployment.go index 1b8a98d0d..cb904584e 100644 --- a/vendor/github.com/appscode/kutil/extensions/v1beta1/deployment.go +++ b/vendor/github.com/appscode/kutil/extensions/v1beta1/deployment.go @@ -57,27 +57,6 @@ func PatchDeployment(c kubernetes.Interface, cur *extensions.Deployment, transfo return out, kutil.VerbPatched, err } -func TryPatchDeployment(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*extensions.Deployment) *extensions.Deployment) (result *extensions.Deployment, err error) { - attempt := 0 - err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { - attempt++ - cur, e2 := c.ExtensionsV1beta1().Deployments(meta.Namespace).Get(meta.Name, metav1.GetOptions{}) - if kerr.IsNotFound(e2) { - return false, e2 - } else if e2 == nil { - result, _, e2 = PatchDeployment(c, cur, transform) - return e2 == nil, nil - } - glog.Errorf("Attempt %d failed to patch Deployment %s/%s due to %v.", attempt, cur.Namespace, cur.Name, e2) - return false, nil - }) - - if err != nil { - err = fmt.Errorf("failed to patch Deployment %s/%s after %d attempts due to %v", meta.Namespace, meta.Name, attempt, err) - } - return -} - func TryUpdateDeployment(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*extensions.Deployment) *extensions.Deployment) (result *extensions.Deployment, err error) { attempt := 0 err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { diff --git a/vendor/github.com/appscode/kutil/extensions/v1beta1/replicaset.go b/vendor/github.com/appscode/kutil/extensions/v1beta1/replicaset.go index 8d353b77d..76692a205 100644 --- a/vendor/github.com/appscode/kutil/extensions/v1beta1/replicaset.go +++ b/vendor/github.com/appscode/kutil/extensions/v1beta1/replicaset.go @@ -57,27 +57,6 @@ func PatchReplicaSet(c kubernetes.Interface, cur *extensions.ReplicaSet, transfo return out, kutil.VerbPatched, err } -func TryPatchReplicaSet(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*extensions.ReplicaSet) *extensions.ReplicaSet) (result *extensions.ReplicaSet, err error) { - attempt := 0 - err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { - attempt++ - cur, e2 := c.ExtensionsV1beta1().ReplicaSets(meta.Namespace).Get(meta.Name, metav1.GetOptions{}) - if kerr.IsNotFound(e2) { - return false, e2 - } else if e2 == nil { - result, _, e2 = PatchReplicaSet(c, cur, transform) - return e2 == nil, nil - } - glog.Errorf("Attempt %d failed to patch ReplicaSet %s/%s due to %v.", attempt, cur.Namespace, cur.Name, e2) - return false, nil - }) - - if err != nil { - err = fmt.Errorf("failed to patch ReplicaSet %s/%s after %d attempts due to %v", meta.Namespace, meta.Name, attempt, err) - } - return -} - func TryUpdateReplicaSet(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*extensions.ReplicaSet) *extensions.ReplicaSet) (result *extensions.ReplicaSet, err error) { attempt := 0 err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { diff --git a/vendor/github.com/appscode/kutil/meta/annotations.go b/vendor/github.com/appscode/kutil/meta/annotations.go index 28bf95d39..a9109fa4d 100644 --- a/vendor/github.com/appscode/kutil/meta/annotations.go +++ b/vendor/github.com/appscode/kutil/meta/annotations.go @@ -30,6 +30,22 @@ func GetString(m map[string]string, key string) string { return m[key] } +func HasKey(m map[string]string, key string) bool { + if m == nil { + return false + } + _, ok := m[key] + return ok +} + +func RemoveKey(m map[string]string, key string) map[string]string { + if m == nil { + return nil + } + delete(m, key) + return m +} + func GetList(m map[string]string, key string) ([]string, error) { if m == nil { return []string{}, nil diff --git a/vendor/github.com/appscode/kutil/rbac/v1beta1/clusterrole.go b/vendor/github.com/appscode/kutil/rbac/v1beta1/clusterrole.go index 9eff82508..93c136d9f 100644 --- a/vendor/github.com/appscode/kutil/rbac/v1beta1/clusterrole.go +++ b/vendor/github.com/appscode/kutil/rbac/v1beta1/clusterrole.go @@ -56,27 +56,6 @@ func PatchClusterRole(c kubernetes.Interface, cur *rbac.ClusterRole, transform f return out, kutil.VerbPatched, err } -func TryPatchClusterRole(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*rbac.ClusterRole) *rbac.ClusterRole) (result *rbac.ClusterRole, err error) { - attempt := 0 - err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { - attempt++ - cur, e2 := c.RbacV1beta1().ClusterRoles().Get(meta.Name, metav1.GetOptions{}) - if kerr.IsNotFound(e2) { - return false, e2 - } else if e2 == nil { - result, _, e2 = PatchClusterRole(c, cur, transform) - return e2 == nil, nil - } - glog.Errorf("Attempt %d failed to patch ClusterRole %s due to %v.", attempt, cur.Name, e2) - return false, nil - }) - - if err != nil { - err = fmt.Errorf("failed to patch ClusterRole %s after %d attempts due to %v", meta.Name, attempt, err) - } - return -} - func TryUpdateClusterRole(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*rbac.ClusterRole) *rbac.ClusterRole) (result *rbac.ClusterRole, err error) { attempt := 0 err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { diff --git a/vendor/github.com/appscode/kutil/rbac/v1beta1/clusterrolebinding.go b/vendor/github.com/appscode/kutil/rbac/v1beta1/clusterrolebinding.go index 57c649bfc..87735ff23 100644 --- a/vendor/github.com/appscode/kutil/rbac/v1beta1/clusterrolebinding.go +++ b/vendor/github.com/appscode/kutil/rbac/v1beta1/clusterrolebinding.go @@ -56,27 +56,6 @@ func PatchClusterRoleBinding(c kubernetes.Interface, cur *rbac.ClusterRoleBindin return out, kutil.VerbPatched, err } -func TryPatchClusterRoleBinding(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*rbac.ClusterRoleBinding) *rbac.ClusterRoleBinding) (result *rbac.ClusterRoleBinding, err error) { - attempt := 0 - err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { - attempt++ - cur, e2 := c.RbacV1beta1().ClusterRoleBindings().Get(meta.Name, metav1.GetOptions{}) - if kerr.IsNotFound(e2) { - return false, e2 - } else if e2 == nil { - result, _, e2 = PatchClusterRoleBinding(c, cur, transform) - return e2 == nil, nil - } - glog.Errorf("Attempt %d failed to patch ClusterRoleBinding %s due to %v.", attempt, cur.Name, e2) - return false, nil - }) - - if err != nil { - err = fmt.Errorf("failed to patch ClusterRoleBinding %s after %d attempts due to %v", meta.Name, attempt, err) - } - return -} - func TryUpdateClusterRoleBinding(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*rbac.ClusterRoleBinding) *rbac.ClusterRoleBinding) (result *rbac.ClusterRoleBinding, err error) { attempt := 0 err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { diff --git a/vendor/github.com/appscode/kutil/rbac/v1beta1/role.go b/vendor/github.com/appscode/kutil/rbac/v1beta1/role.go index 2858ba57d..692485698 100644 --- a/vendor/github.com/appscode/kutil/rbac/v1beta1/role.go +++ b/vendor/github.com/appscode/kutil/rbac/v1beta1/role.go @@ -56,27 +56,6 @@ func PatchRole(c kubernetes.Interface, cur *rbac.Role, transform func(*rbac.Role return out, kutil.VerbPatched, err } -func TryPatchRole(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*rbac.Role) *rbac.Role) (result *rbac.Role, err error) { - attempt := 0 - err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { - attempt++ - cur, e2 := c.RbacV1beta1().Roles(meta.Namespace).Get(meta.Name, metav1.GetOptions{}) - if kerr.IsNotFound(e2) { - return false, e2 - } else if e2 == nil { - result, _, e2 = PatchRole(c, cur, transform) - return e2 == nil, nil - } - glog.Errorf("Attempt %d failed to patch Role %s/%s due to %v.", attempt, cur.Namespace, cur.Name, e2) - return false, nil - }) - - if err != nil { - err = fmt.Errorf("failed to patch Role %s/%s after %d attempts due to %v", meta.Namespace, meta.Name, attempt, err) - } - return -} - func TryUpdateRole(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*rbac.Role) *rbac.Role) (result *rbac.Role, err error) { attempt := 0 err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { diff --git a/vendor/github.com/appscode/kutil/rbac/v1beta1/rolebinding.go b/vendor/github.com/appscode/kutil/rbac/v1beta1/rolebinding.go index 6eca93e58..6589237d6 100644 --- a/vendor/github.com/appscode/kutil/rbac/v1beta1/rolebinding.go +++ b/vendor/github.com/appscode/kutil/rbac/v1beta1/rolebinding.go @@ -56,27 +56,6 @@ func PatchRoleBinding(c kubernetes.Interface, cur *rbac.RoleBinding, transform f return out, kutil.VerbPatched, err } -func TryPatchRoleBinding(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*rbac.RoleBinding) *rbac.RoleBinding) (result *rbac.RoleBinding, err error) { - attempt := 0 - err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) { - attempt++ - cur, e2 := c.RbacV1beta1().RoleBindings(meta.Namespace).Get(meta.Name, metav1.GetOptions{}) - if kerr.IsNotFound(e2) { - return false, e2 - } else if e2 == nil { - result, _, e2 = PatchRoleBinding(c, cur, transform) - return e2 == nil, nil - } - glog.Errorf("Attempt %d failed to patch RoleBinding %s/%s due to %v.", attempt, cur.Namespace, cur.Name, e2) - return false, nil - }) - - if err != nil { - err = fmt.Errorf("failed to patch RoleBinding %s/%s after %d attempts due to %v", meta.Namespace, meta.Name, attempt, err) - } - return -} - func TryUpdateRoleBinding(c kubernetes.Interface, meta metav1.ObjectMeta, transform func(*rbac.RoleBinding) *rbac.RoleBinding) (result *rbac.RoleBinding, err error) { attempt := 0 err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) {