Skip to content

Commit 671ccad

Browse files
committed
Update deps to make envtest work again
1 parent 2a7f656 commit 671ccad

File tree

7 files changed

+387
-412
lines changed

7 files changed

+387
-412
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
99
all: fmt vet build
1010

1111
.PHONY: build
12-
build:
12+
build:
1313
CGO_ENABLED=0 go build
1414

1515

1616
run: fmt vet ## Run against the configured Kubernetes cluster in ~/.kube/config
1717
go run ./main.go
1818

1919
.PHONY: test
20-
test: fmt ## Run tests
20+
test: fmt ## Run tests
2121
go test -tags="" ./... -coverprofile cover.out
2222

2323
.PHONY: integration-test
24-
integration-test: export ENVTEST_K8S_VERSION = 1.19.x
24+
integration-test: export ENVTEST_K8S_VERSION = 1.24.x
2525
integration-test: ## Run integration tests with envtest
2626
mkdir -p ${ENVTEST_ASSETS_DIR}
2727
$(setup-envtest) use '$(ENVTEST_K8S_VERSION)!'

config/rbac/role.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
21
---
32
apiVersion: rbac.authorization.k8s.io/v1
43
kind: ClusterRole
54
metadata:
6-
creationTimestamp: null
75
name: controller-manager
86
rules:
97
- apiGroups:

controllers/inplace_controller.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,15 @@ func (r *InplaceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
6868
return ctrl.Result{}, nil
6969
}
7070

71-
return ctrl.Result{}, resizePVCsInplace(ctx, r.Client, stsEntity.Pvcs)
71+
err = resizePVCsInplace(ctx, r.Client, stsEntity.Pvcs)
72+
if err != nil {
73+
r.Recorder.Event(sts, "Warning", "ResizeFailed", "There was an error during the PVC resize")
74+
return ctrl.Result{}, err
75+
}
76+
77+
r.Recorder.Event(sts, "Normal", "ResizeSuccessful", "All PVCs have been resized successfully")
78+
79+
return ctrl.Result{}, nil
7280
}
7381

7482
// SetupWithManager sets up the controller with the Manager.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//go:build integration
2+
// +build integration
3+
4+
package controllers
5+
6+
import (
7+
"context"
8+
"testing"
9+
"time"
10+
11+
"github.com/stretchr/testify/require"
12+
appsv1 "k8s.io/api/apps/v1"
13+
batchv1 "k8s.io/api/batch/v1"
14+
corev1 "k8s.io/api/core/v1"
15+
rbacv1 "k8s.io/api/rbac/v1"
16+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17+
"k8s.io/apimachinery/pkg/runtime"
18+
ctrl "sigs.k8s.io/controller-runtime"
19+
"sigs.k8s.io/controller-runtime/pkg/client"
20+
"sigs.k8s.io/controller-runtime/pkg/envtest"
21+
)
22+
23+
const (
24+
testLabelName = "mylabel"
25+
)
26+
27+
func TestInplaceController(t *testing.T) {
28+
ctx, cancel := context.WithCancel(context.Background())
29+
defer cancel()
30+
c, stop := startInplaceTestReconciler(t, ctx, "")
31+
defer stop()
32+
33+
t.Run("InplaceE2E", func(t *testing.T) {
34+
35+
t.Run("Don't scale down correct StatfulSets", func(t *testing.T) {
36+
t.Parallel()
37+
ctx := context.Background()
38+
ns := "e2e1"
39+
require := require.New(t)
40+
require.NoError(c.Create(ctx, &corev1.Namespace{
41+
ObjectMeta: metav1.ObjectMeta{
42+
Name: ns,
43+
},
44+
}))
45+
sts := newTestStatefulSet(ns, "test", 1, "2G")
46+
// sts.Labels[testLabelName] = "true"
47+
require.NoError(c.Create(ctx, newSource(ns, "data-test-0", "2G",
48+
func(pvc *corev1.PersistentVolumeClaim) *corev1.PersistentVolumeClaim {
49+
pvc.Labels = sts.Spec.Selector.MatchLabels
50+
return pvc
51+
})))
52+
require.NoError(c.Create(ctx, sts))
53+
54+
consistently(t, func() bool {
55+
return stsExists(ctx, c, sts)
56+
}, duration, interval, "Sts exists")
57+
58+
})
59+
})
60+
}
61+
62+
// startInplaceTestReconciler sets up a separate test env and starts the controller
63+
func startInplaceTestReconciler(t *testing.T, ctx context.Context, crname string) (client.Client, func() error) {
64+
req := require.New(t)
65+
66+
testEnv := &envtest.Environment{}
67+
conf, err := testEnv.Start()
68+
req.NoError(err)
69+
70+
s := runtime.NewScheme()
71+
req.NoError(appsv1.AddToScheme(s))
72+
req.NoError(corev1.AddToScheme(s))
73+
req.NoError(batchv1.AddToScheme(s))
74+
req.NoError(rbacv1.AddToScheme(s))
75+
76+
mgr, err := ctrl.NewManager(conf, ctrl.Options{
77+
Scheme: s,
78+
})
79+
req.NoError(err)
80+
req.NoError((&InplaceReconciler{
81+
Client: mgr.GetClient(),
82+
Scheme: mgr.GetScheme(),
83+
Recorder: mgr.GetEventRecorderFor("statefulset-resize-controller"),
84+
RequeueAfter: time.Second,
85+
LabelName: testLabelName,
86+
}).SetupWithManager(mgr))
87+
go func() {
88+
req.NoError(mgr.Start(ctx))
89+
}()
90+
91+
return mgr.GetClient(), testEnv.Stop
92+
}

go.mod

Lines changed: 86 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,92 @@
11
module github.com/vshn/statefulset-resize-controller
22

3-
go 1.16
3+
go 1.20
44

55
require (
6-
github.com/stretchr/testify v1.7.0
7-
go.uber.org/zap v1.18.1
8-
k8s.io/api v0.21.3
9-
k8s.io/apimachinery v0.21.3
10-
k8s.io/client-go v0.21.3
11-
k8s.io/utils v0.0.0-20210722164352-7f3ee0f31471
12-
sigs.k8s.io/controller-runtime v0.9.5
13-
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20210713022429-8b55f85c90c3
14-
sigs.k8s.io/controller-tools v0.6.2
6+
github.com/stretchr/testify v1.8.4
7+
go.uber.org/zap v1.25.0
8+
k8s.io/api v0.27.4
9+
k8s.io/apimachinery v0.27.4
10+
k8s.io/client-go v0.27.4
11+
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
12+
sigs.k8s.io/controller-runtime v0.15.0
13+
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20230728161957-7f0c6dc440f3
14+
sigs.k8s.io/controller-tools v0.12.1
1515
sigs.k8s.io/kustomize/kustomize/v3 v3.10.0
1616
)
17+
18+
require (
19+
github.com/beorn7/perks v1.0.1 // indirect
20+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
21+
github.com/davecgh/go-spew v1.1.1 // indirect
22+
github.com/emicklei/go-restful/v3 v3.10.2 // indirect
23+
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
24+
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
25+
github.com/fatih/color v1.15.0 // indirect
26+
github.com/fsnotify/fsnotify v1.6.0 // indirect
27+
github.com/go-errors/errors v1.4.2 // indirect
28+
github.com/go-logr/logr v1.2.4 // indirect
29+
github.com/go-logr/zapr v1.2.4 // indirect
30+
github.com/go-openapi/jsonpointer v0.20.0 // indirect
31+
github.com/go-openapi/jsonreference v0.20.2 // indirect
32+
github.com/go-openapi/swag v0.22.4 // indirect
33+
github.com/gobuffalo/flect v1.0.2 // indirect
34+
github.com/gogo/protobuf v1.3.2 // indirect
35+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
36+
github.com/golang/protobuf v1.5.3 // indirect
37+
github.com/google/gnostic v0.6.9 // indirect
38+
github.com/google/go-cmp v0.5.9 // indirect
39+
github.com/google/gofuzz v1.2.0 // indirect
40+
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
41+
github.com/google/uuid v1.3.0 // indirect
42+
github.com/imdario/mergo v0.3.16 // indirect
43+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
44+
github.com/josharian/intern v1.0.0 // indirect
45+
github.com/json-iterator/go v1.1.12 // indirect
46+
github.com/mailru/easyjson v0.7.7 // indirect
47+
github.com/mattn/go-colorable v0.1.13 // indirect
48+
github.com/mattn/go-isatty v0.0.19 // indirect
49+
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
50+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
51+
github.com/modern-go/reflect2 v1.0.2 // indirect
52+
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
53+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
54+
github.com/pkg/errors v0.9.1 // indirect
55+
github.com/pmezard/go-difflib v1.0.0 // indirect
56+
github.com/prometheus/client_golang v1.16.0 // indirect
57+
github.com/prometheus/client_model v0.4.0 // indirect
58+
github.com/prometheus/common v0.44.0 // indirect
59+
github.com/prometheus/procfs v0.11.1 // indirect
60+
github.com/spf13/afero v1.9.5 // indirect
61+
github.com/spf13/cobra v1.7.0 // indirect
62+
github.com/spf13/pflag v1.0.5 // indirect
63+
github.com/xlab/treeprint v1.2.0 // indirect
64+
go.starlark.net v0.0.0-20230731234521-9b46791399bf // indirect
65+
go.uber.org/multierr v1.11.0 // indirect
66+
golang.org/x/mod v0.12.0 // indirect
67+
golang.org/x/net v0.13.0 // indirect
68+
golang.org/x/oauth2 v0.10.0 // indirect
69+
golang.org/x/sys v0.10.0 // indirect
70+
golang.org/x/term v0.10.0 // indirect
71+
golang.org/x/text v0.11.0 // indirect
72+
golang.org/x/time v0.3.0 // indirect
73+
golang.org/x/tools v0.11.1 // indirect
74+
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
75+
google.golang.org/appengine v1.6.7 // indirect
76+
google.golang.org/protobuf v1.31.0 // indirect
77+
gopkg.in/inf.v0 v0.9.1 // indirect
78+
gopkg.in/yaml.v2 v2.4.0 // indirect
79+
gopkg.in/yaml.v3 v3.0.1 // indirect
80+
k8s.io/apiextensions-apiserver v0.27.4 // indirect
81+
k8s.io/component-base v0.27.4 // indirect
82+
k8s.io/klog/v2 v2.100.1 // indirect
83+
k8s.io/kube-openapi v0.0.0-20230525220651-2546d827e515 // indirect
84+
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
85+
sigs.k8s.io/kustomize/api v0.13.4 // indirect
86+
sigs.k8s.io/kustomize/cmd/config v0.11.2 // indirect
87+
sigs.k8s.io/kustomize/kyaml v0.14.2 // indirect
88+
sigs.k8s.io/structured-merge-diff/v4 v4.3.0 // indirect
89+
sigs.k8s.io/yaml v1.3.0 // indirect
90+
)
91+
92+
replace github.com/googleapis/gnostic-models => github.com/googleapis/gnostic v0.5.5

0 commit comments

Comments
 (0)