Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update kubernetes client to v0.21.1 #301

Merged
merged 2 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ linters:
- gci
- goconst
- gocritic
- gocyclo
- goimports
- golint
- gosimple
Expand Down Expand Up @@ -213,6 +212,9 @@ linters:
- nlreturn
# Opinionated and sometimes wrong.
- paralleltest
# This linter isn't that helpful since it's not immediately obvious how to
# address its lints (for cyclomatic complexity).
- gocyclo
disable-all: false
presets:
# bodyclose, errcheck, gosec, govet, scopelint, staticcheck, typecheck
Expand Down
26 changes: 11 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,18 @@ require (
github.com/cirocosta/grafana-sync v0.0.0-20181123215626-6cbb4a9501c1
github.com/d4l3k/messagediff v1.2.1
github.com/emicklei/go-restful v2.9.6+incompatible // indirect
github.com/evanphx/json-patch v4.5.0+incompatible
github.com/evanphx/json-patch v4.9.0+incompatible
github.com/fortytw2/leaktest v1.3.0 // indirect
github.com/fossas/fossa-cli v1.0.30
github.com/garethr/kubeval v0.0.0-20180821130434-c44f5193dc94
github.com/go-openapi/inflect v0.19.0 // indirect
github.com/go-openapi/runtime v0.19.5 // indirect
github.com/go-openapi/spec v0.19.3
github.com/go-openapi/spec v0.19.5
github.com/go-swagger/go-swagger v0.19.0
github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013 // indirect
github.com/gogo/protobuf v1.3.1
github.com/gogo/protobuf v1.3.2
github.com/golang/mock v1.4.4
github.com/golangci/golangci-lint v1.37.1
github.com/googleapis/gnostic v0.3.1 // indirect
github.com/hashicorp/go-retryablehttp v0.6.0
github.com/m3db/build-tools v0.0.0-20181013000606-edd1bdd1df8a
github.com/m3db/m3 v1.1.1-0.20210302095536-802492679da1
Expand All @@ -33,17 +32,14 @@ require (
github.com/urfave/cli v1.22.2 // indirect
go.uber.org/atomic v1.6.0
go.uber.org/zap v1.13.0
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f
google.golang.org/appengine v1.6.2 // indirect
k8s.io/api v0.17.3
k8s.io/apiextensions-apiserver v0.17.2
k8s.io/apimachinery v0.17.3
k8s.io/client-go v0.17.3
k8s.io/code-generator v0.17.2
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac // indirect
k8s.io/kube-openapi v0.0.0-20200410145947-bcb3869e6f29
k8s.io/utils v0.0.0-20200603063816-c1c6865ac451
sigs.k8s.io/yaml v1.2.0 // indirect
golang.org/x/lint v0.0.0-20200302205851-738671d3881b
k8s.io/api v0.21.1
k8s.io/apiextensions-apiserver v0.21.1
k8s.io/apimachinery v0.21.1
k8s.io/client-go v0.21.1
k8s.io/code-generator v0.21.1
k8s.io/kube-openapi v0.0.0-20210305001622-591a79e4bda7
k8s.io/utils v0.0.0-20201110183641-67b214c5f920
)

replace github.com/apache/thrift => github.com/m3db/thrift v0.0.0-20151001171628-53dd39833a08
Expand Down
352 changes: 173 additions & 179 deletions go.sum

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions integration/e2e/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package e2e

import (
"context"
"sort"
"testing"
"time"
Expand All @@ -43,8 +44,9 @@ const (

func TestCreateCluster_Regional(t *testing.T) {
h := harness.Global
ctx := context.Background()

cluster, err := h.CreateM3DBCluster("cluster-regional.yaml")
cluster, err := h.CreateM3DBCluster(ctx, "cluster-regional.yaml")
require.NoError(t, err)

cl, err := h.NewPlacementClient(cluster)
Expand Down Expand Up @@ -82,8 +84,9 @@ func TestCreateCluster_Regional(t *testing.T) {

func TestCreateCluster_Zonal(t *testing.T) {
h := harness.Global
ctx := context.Background()

cluster, err := h.CreateM3DBCluster("cluster-zonal.yaml")
cluster, err := h.CreateM3DBCluster(ctx, "cluster-zonal.yaml")
require.NoError(t, err)

cl, err := h.NewPlacementClient(cluster)
Expand Down
10 changes: 7 additions & 3 deletions integration/harness/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package harness

import (
"context"
"encoding/json"
"errors"
"fmt"
Expand All @@ -34,6 +35,7 @@ import (

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
jeromefroe marked this conversation as resolved.
Show resolved Hide resolved
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/util/yaml"

Expand All @@ -45,7 +47,7 @@ const (
etcdHealthTimeout = 5 * time.Minute
)

func (h *Harness) createEtcdCluster() error {
func (h *Harness) createEtcdCluster(ctx context.Context) error {
f, err := os.Open("../manifests/etcd.yaml")
if err != nil {
return err
Expand Down Expand Up @@ -73,13 +75,15 @@ func (h *Harness) createEtcdCluster() error {
clusterSvc,
} {
h.Logger.Info("creating etcd service", zap.String("service", svc.Name))
if _, err := h.KubeClient.CoreV1().Services(h.Namespace).Create(svc); err != nil {
_, err := h.KubeClient.CoreV1().Services(h.Namespace).Create(ctx, svc, v1.CreateOptions{})
if err != nil {
return err
}
}

h.Logger.Info("creating etcd statefulset", zap.String("statefulset", statefulSet.Name))
if _, err := h.KubeClient.AppsV1().StatefulSets(h.Namespace).Create(statefulSet); err != nil {
_, err = h.KubeClient.AppsV1().StatefulSets(h.Namespace).Create(ctx, statefulSet, v1.CreateOptions{})
if err != nil {
return err
}

Expand Down
38 changes: 22 additions & 16 deletions integration/harness/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package harness

import (
"context"
"fmt"

clientset "github.com/m3db/m3db-operator/pkg/client/clientset/versioned"
Expand Down Expand Up @@ -95,11 +96,11 @@ func buildSuite(opts *suiteOpts) (*Harness, error) {
return h, nil
}

func (h *Harness) ensureNamespace() error {
ns, err := h.KubeClient.CoreV1().Namespaces().Get(h.Namespace, metav1.GetOptions{})
func (h *Harness) ensureNamespace(ctx context.Context) error {
ns, err := h.KubeClient.CoreV1().Namespaces().Get(ctx, h.Namespace, metav1.GetOptions{})
if err != nil {
if errors.IsNotFound(err) {
return h.createNamespace(defaultNamespace)
return h.createNamespace(ctx, defaultNamespace)
}
return err
}
Expand All @@ -112,46 +113,51 @@ func (h *Harness) ensureNamespace() error {
return nil
}

func (h *Harness) setupSuite() error {
if err := h.ensureNamespace(); err != nil {
func (h *Harness) setupSuite(ctx context.Context) error {
if err := h.ensureNamespace(ctx); err != nil {
return err
}

if err := h.installOperator(); err != nil {
if err := h.installOperator(ctx); err != nil {
return err
}

if err := h.createEtcdCluster(); err != nil {
if err := h.createEtcdCluster(ctx); err != nil {
return err
}

return nil
}

func (h *Harness) createNamespace(ns string) error {
func (h *Harness) createNamespace(ctx context.Context, ns string) error {
if h.Flags.SkipCreateNamespace {
return nil
}

h.Logger.Info("creating namespace", zap.String("namespace", ns))
_, err := h.KubeClient.CoreV1().Namespaces().Create(&corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: ns,
_, err := h.KubeClient.CoreV1().Namespaces().Create(
ctx,
&corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: ns,
},
},
})
metav1.CreateOptions{},
)
return err
}

func (h *Harness) teardownSuite() error {
func (h *Harness) teardownSuite(ctx context.Context) error {
if !h.Flags.SkipDeleteRBAC {
h.Logger.Info("deleting clusterrole", zap.String("clusterrole", defaultClusterRoleName))
err := h.KubeClient.RbacV1().ClusterRoles().Delete(defaultClusterRoleName, nil)
err := h.KubeClient.RbacV1().ClusterRoles().Delete(ctx, defaultClusterRoleName, metav1.DeleteOptions{})
if err != nil {
return err
}

h.Logger.Info("deleting clusterrolebinding", zap.String("clusterrolebinding", defaultClusterRoleBindingName))
err = h.KubeClient.RbacV1().ClusterRoleBindings().Delete(defaultClusterRoleBindingName, nil)
err = h.KubeClient.RbacV1().ClusterRoleBindings().
Delete(ctx, defaultClusterRoleBindingName, metav1.DeleteOptions{})
if err != nil {
return err
}
Expand All @@ -162,7 +168,7 @@ func (h *Harness) teardownSuite() error {
}

h.Logger.Info("deleting namespace")
err := h.KubeClient.CoreV1().Namespaces().Delete(h.Namespace, nil)
err := h.KubeClient.CoreV1().Namespaces().Delete(ctx, h.Namespace, metav1.DeleteOptions{})
if err != nil {
return err
}
Expand Down
7 changes: 5 additions & 2 deletions integration/harness/m3dbcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@
package harness

import (
"context"
"os"
"path/filepath"

myspec "github.com/m3db/m3db-operator/pkg/apis/m3dboperator/v1alpha1"

v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
jeromefroe marked this conversation as resolved.
Show resolved Hide resolved
"k8s.io/apimachinery/pkg/util/yaml"

"go.uber.org/zap"
)

// CreateM3DBCluster creates an m3db cluster from a predefined manifest.
func (h *Harness) CreateM3DBCluster(filename string) (*myspec.M3DBCluster, error) {
func (h *Harness) CreateM3DBCluster(ctx context.Context, filename string) (*myspec.M3DBCluster, error) {
path := filepath.Join("../manifests", filename)

f, err := os.Open(path)
Expand All @@ -56,7 +58,8 @@ func (h *Harness) CreateM3DBCluster(filename string) (*myspec.M3DBCluster, error
}

h.Logger.Info("creating m3dbcluster", zap.String("m3dbcluster", cluster.Name))
cluster, err = h.CRDClient.OperatorV1alpha1().M3DBClusters(h.Namespace).Create(cluster)
cluster, err = h.CRDClient.OperatorV1alpha1().M3DBClusters(h.Namespace).
Create(ctx, cluster, v1.CreateOptions{})
if err != nil {
return nil, err
}
Expand Down
13 changes: 8 additions & 5 deletions integration/harness/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@
package harness

import (
"context"
"os"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/yaml"

"go.uber.org/zap"
)

func (h *Harness) installOperator() error {
func (h *Harness) installOperator(ctx context.Context) error {
f, err := os.Open("../manifests/operator.yaml")
if err != nil {
return err
Expand All @@ -59,7 +61,8 @@ func (h *Harness) installOperator() error {
}

h.Logger.Info("creating serviceaccount", zap.String("serviceaccount", sa.Name))
if _, err := h.KubeClient.CoreV1().ServiceAccounts(h.Namespace).Create(sa); err != nil {
if _, err := h.KubeClient.CoreV1().ServiceAccounts(h.Namespace).
Create(ctx, sa, v1.CreateOptions{}); err != nil {
if !errors.IsAlreadyExists(err) {
return err
}
Expand All @@ -70,15 +73,15 @@ func (h *Harness) installOperator() error {

if !h.Flags.SkipCreateRBAC {
h.Logger.Info("creating clusterrole", zap.String("role", role.Name))
if _, err := rc.ClusterRoles().Create(role); err != nil {
if _, err := rc.ClusterRoles().Create(ctx, role, v1.CreateOptions{}); err != nil {
if !errors.IsAlreadyExists(err) {
return err
}
h.Logger.Info("found existing clusterrole")
}

h.Logger.Info("creating rolebinding", zap.String("rolebinding", rb.Name))
if _, err := rc.ClusterRoleBindings().Create(rb); err != nil {
if _, err := rc.ClusterRoleBindings().Create(ctx, rb, v1.CreateOptions{}); err != nil {
if !errors.IsAlreadyExists(err) {
return err
}
Expand All @@ -87,6 +90,6 @@ func (h *Harness) installOperator() error {
}

h.Logger.Info("creating statefulset", zap.String("statefulset", sts.Name))
_, err = h.KubeClient.AppsV1().StatefulSets(h.Namespace).Create(sts)
_, err = h.KubeClient.AppsV1().StatefulSets(h.Namespace).Create(ctx, sts, v1.CreateOptions{})
return err
}
6 changes: 4 additions & 2 deletions integration/harness/run_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package harness

import (
"context"
"flag"
"fmt"
"os"
Expand Down Expand Up @@ -100,15 +101,16 @@ func RunSuite(m *testing.M) {
logger.Fatal("error building suite", zap.Error(err))
}

if err := harness.setupSuite(); err != nil {
ctx := context.Background()
if err := harness.setupSuite(ctx); err != nil {
logger.Fatal("error setting up suite", zap.Error(err))
}

Global = harness

code := m.Run()

if err := harness.teardownSuite(); err != nil {
if err := harness.teardownSuite(ctx); err != nil {
logger.Fatal("error tearing down suite")
}

Expand Down
Loading