Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Add failback logic when working on k8s 1.16+ #371

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions pkg/util/k8sutil/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/coreos/etcd-operator/pkg/util/retryutil"
vaultapi "github.com/hashicorp/vault/api"
appsv1beta1 "k8s.io/api/apps/v1beta1"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down Expand Up @@ -283,7 +283,17 @@ func DeployVault(kubecli kubernetes.Interface, v *api.VaultService) error {
AddOwnerRefToObject(d, AsOwner(v))
_, err := kubecli.AppsV1beta1().Deployments(v.Namespace).Create(d)
if err != nil && !apierrors.IsAlreadyExists(err) {
return err
// after 1.15, the deployment moves to v1 per https://v1-16.docs.kubernetes.io/zh/docs/concepts/workloads/controllers/deployment/
if !apierrors.IsNotFound(err) {
return err
}

// then try fail back on different versioning namespace
_, err = kubecli.AppsV1().Deployments(v.Namespace).Create(d)

if err != nil && !apierrors.IsAlreadyExists(err) {
return err
}
}

svc := &v1.Service{
Expand Down