Skip to content

Commit

Permalink
Bump k8s (#191)
Browse files Browse the repository at this point in the history
* Bump k8s to 1.27

* tests

* fix linter

* linting

* wip

* webhook works

* remove decoder injection

* revert not known change

* revert ptr changes

* migrate cache

* disable caching for job

* remove deprecated methods

---------

Co-authored-by: Piotr Halama <[email protected]>
  • Loading branch information
dbadura and halamix2 authored Feb 7, 2024
1 parent 2fbe53d commit 68cc849
Show file tree
Hide file tree
Showing 14 changed files with 311 additions and 1,218 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/warden-verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: true
cache: false
- uses: golangci/golangci-lint-action@v3
with:
version: v1.54
Expand Down Expand Up @@ -63,4 +63,4 @@ jobs:
run: make verify-on-cluster
- name: Show Warden Logs
if: failure()
run: kubectl logs -l app=warden -n kyma-system --prefix=true;
run: kubectl logs -l app=warden -n kyma-system --prefix=true;
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Image URL to use all building/pushing image targets
IMG ?= controller:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.25.0
ENVTEST_K8S_VERSION = 1.27.1

# TEST_COVER_OUT determines path for the output file with coverage
TEST_COVER_OUT ?= $(shell pwd)/cover.out
Expand Down
22 changes: 13 additions & 9 deletions cmd/admission/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"k8s.io/apimachinery/pkg/fields"
"os"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/healthz"

"github.com/go-logr/zapr"
Expand All @@ -25,6 +26,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/manager"
ctrlwebhook "sigs.k8s.io/controller-runtime/pkg/webhook"
ctrladmission "sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

var (
Expand Down Expand Up @@ -107,18 +109,22 @@ func main() {

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), manager.Options{
Scheme: scheme,
Port: appConfig.Admission.Port,
MetricsBindAddress: ":9090",
Logger: logrZap,
HealthProbeBindAddress: ":8090",
NewCache: cache.BuilderWithOptions(cache.Options{
SelectorsByObject: cache.SelectorsByObject{
WebhookServer: ctrlwebhook.NewServer(ctrlwebhook.Options{
CertName: certs.CertFile,
KeyName: certs.KeyFile,
Port: appConfig.Admission.Port,
}),
Cache: cache.Options{
ByObject: map[client.Object]cache.ByObject{
&corev1.Secret{}: {
Field: fields.SelectorFromSet(fields.Set{"metadata.name": appConfig.Admission.SecretName,
"metadata.namespace": appConfig.Admission.SystemNamespace}),
},
},
}),
},
})
if err != nil {
logger.Error("failed to start manager", err.Error())
Expand All @@ -137,7 +143,6 @@ func main() {
deployName,
addOwnerRef,
logger); err != nil {

logger.Error("failed to setup webhook resource controller ", err.Error())
os.Exit(5)
}
Expand All @@ -155,14 +160,13 @@ func main() {
logger.Info("setting up webhook server")
// webhook server setup
whs := mgr.GetWebhookServer()
whs.CertName = certs.CertFile
whs.KeyName = certs.KeyFile
decoder := ctrladmission.NewDecoder(mgr.GetScheme())
whs.Register(admission.ValidationPath, &ctrlwebhook.Admission{
Handler: admission.NewValidationWebhook(logger.With("webhook", "validation")),
Handler: admission.NewValidationWebhook(logger.With("webhook", "validation"), decoder),
})

whs.Register(admission.DefaultingPath, &ctrlwebhook.Admission{
Handler: admission.NewDefaultingWebhook(mgr.GetClient(), validatorSvc, appConfig.Admission.Timeout, appConfig.Admission.StrictMode, logger.With("webhook", "defaulting")),
Handler: admission.NewDefaultingWebhook(mgr.GetClient(), validatorSvc, appConfig.Admission.Timeout, appConfig.Admission.StrictMode, decoder, logger.With("webhook", "defaulting")),
})

logger.Info("starting the controller-manager")
Expand Down
24 changes: 8 additions & 16 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import (
"fmt"
"github.com/go-logr/zapr"
"github.com/kyma-project/warden/internal/logging"
corev1 "k8s.io/api/core/v1"
"os"
"sigs.k8s.io/controller-runtime/pkg/cache"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"

"github.com/kyma-project/warden/internal/config"
"github.com/kyma-project/warden/internal/controllers"
Expand All @@ -33,12 +36,10 @@ import (

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/healthz"
zapk8s "sigs.k8s.io/controller-runtime/pkg/log/zap"
//+kubebuilder:scaffold:imports
Expand Down Expand Up @@ -99,21 +100,12 @@ func main() {
LeaderElection: appConfig.Operator.LeaderElect,
LeaderElectionID: "c3790980.warden.kyma-project.io",
Logger: logrZap,
ClientDisableCacheFor: []ctrlclient.Object{
&corev1.Secret{},
&corev1.ConfigMap{},
Cache: cache.Options{
ByObject: map[ctrlclient.Object]cache.ByObject{
&corev1.Secret{}: {},
&corev1.ConfigMap{}: {},
},
},
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
// when the Manager ends. This requires the binary to immediately end when the
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
// speeds up voluntary leader transitions as the new leader don't have to wait
// LeaseDuration time first.
//
// In the default scaffold provided, the program ends immediately after
// the manager stops, so would be fine to enable this option. However,
// if you are doing or is intended to do any operation such as perform cleanups
// after the manager stops then its usage might be unsafe.
// LeaderElectionReleaseOnCancel: true,
})
if err != nil {
logger.Error(err, "unable to start manager")
Expand Down
88 changes: 39 additions & 49 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,54 @@ go 1.21

require (
github.com/docker/distribution v2.8.1+incompatible
github.com/fsnotify/fsnotify v1.5.4
github.com/go-logr/zapr v1.2.3
github.com/fsnotify/fsnotify v1.6.0
github.com/go-logr/zapr v1.2.4
github.com/google/go-containerregistry v0.12.1
github.com/google/uuid v1.1.2
github.com/google/uuid v1.3.0
github.com/kyma-project/kyma/common/logging v0.0.0-20230202094231-eaaef03503fe
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.0
github.com/stretchr/testify v1.8.1
github.com/theupdateframework/notary v0.7.0
go.uber.org/zap v1.21.0
golang.org/x/net v0.7.0
gomodules.xyz/jsonpatch/v2 v2.2.0
go.uber.org/zap v1.24.0
golang.org/x/net v0.19.0
gomodules.xyz/jsonpatch/v2 v2.3.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.25.4
k8s.io/apiextensions-apiserver v0.25.0
k8s.io/apimachinery v0.25.4
k8s.io/client-go v0.25.4
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed
sigs.k8s.io/controller-runtime v0.13.0
k8s.io/api v0.27.10
k8s.io/apiextensions-apiserver v0.27.10
k8s.io/apimachinery v0.27.10
k8s.io/client-go v0.27.10
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
sigs.k8s.io/controller-runtime v0.15.3
)

require (
cloud.google.com/go v0.97.0 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.27 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.20 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/cli v20.10.20+incompatible // indirect
github.com/docker/docker v20.10.20+incompatible // indirect
github.com/docker/docker-credential-helpers v0.7.0 // indirect
github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c // indirect
github.com/docker/go-metrics v0.0.0-20180209012529-399ea8c73916 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/gorilla/mux v1.7.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/miekg/pkcs11 v1.0.2 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand All @@ -70,30 +60,30 @@ require (
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/prometheus/client_golang v1.15.1 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect
golang.org/x/oauth2 v0.1.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/component-base v0.25.0 // indirect
k8s.io/klog/v2 v2.70.1 // indirect
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
k8s.io/component-base v0.27.10 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit 68cc849

Please sign in to comment.