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 dependencies to K8s 1.28 #1493

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package controllers_test
import (
"context"
"path/filepath"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
"testing"

"k8s.io/client-go/util/retry"
Expand Down Expand Up @@ -84,8 +85,10 @@ var _ = BeforeSuite(func() {
Expect(err).NotTo(HaveOccurred())

mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme.Scheme,
MetricsBindAddress: "0",
Scheme: scheme.Scheme,
Metrics: server.Options{
BindAddress: "0",
},
})
Expect(err).ToNot(HaveOccurred())

Expand Down
47 changes: 24 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ require (
github.com/cloudflare/cfssl v1.6.4
github.com/eclipse/paho.mqtt.golang v1.4.3
github.com/elastic/crd-ref-docs v0.0.9
github.com/go-logr/logr v1.2.4
github.com/go-logr/logr v1.3.0
github.com/go-stomp/stomp v2.1.4+incompatible
github.com/michaelklishin/rabbit-hole/v2 v2.15.0
github.com/mikefarah/yq/v4 v4.35.2
github.com/onsi/ginkgo/v2 v2.13.0
github.com/onsi/ginkgo/v2 v2.13.1
github.com/onsi/gomega v1.30.0
github.com/rabbitmq/amqp091-go v1.9.0
github.com/rabbitmq/rabbitmq-stream-go-client v1.3.0
github.com/sclevine/yj v0.0.0-20200815061347-554173e71934
golang.org/x/mod v0.13.0
golang.org/x/net v0.17.0
golang.org/x/mod v0.14.0
golang.org/x/net v0.18.0
golang.org/x/vuln v1.0.1
gopkg.in/ini.v1 v1.67.0
k8s.io/api v0.28.1
k8s.io/apimachinery v0.28.2
k8s.io/client-go v0.28.1
k8s.io/klog/v2 v2.100.1
k8s.io/api v0.28.4
k8s.io/apimachinery v0.28.4
k8s.io/client-go v0.28.4
k8s.io/klog/v2 v2.110.1
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
sigs.k8s.io/controller-runtime v0.15.1
sigs.k8s.io/controller-runtime v0.16.3
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20220217024943-cfd92767d28e
sigs.k8s.io/controller-tools v0.13.0
sigs.k8s.io/kind v0.20.0
sigs.k8s.io/kustomize/kustomize/v5 v5.1.1
sigs.k8s.io/kustomize/kustomize/v5 v5.2.1
)

require (
Expand All @@ -44,7 +44,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dimchansky/utfbom v1.1.1 // indirect
github.com/elliotchance/orderedmap v1.5.0 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fatih/color v1.15.0 // indirect
Expand Down Expand Up @@ -108,32 +108,33 @@ require (
github.com/zmap/zcrypto v0.0.0-20210511125630-18f1e0152cfc // indirect
github.com/zmap/zlint/v3 v3.1.0 // indirect
go.starlark.net v0.0.0-20230814145427-12f4cb8177e4 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
go.uber.org/zap v1.25.0 // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/evanphx/json-patch.v5 v5.6.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.28.0 // indirect
k8s.io/component-base v0.28.0 // indirect
k8s.io/apiextensions-apiserver v0.28.3 // indirect
k8s.io/component-base v0.28.3 // indirect
k8s.io/kube-openapi v0.0.0-20230816210353-14e408962443 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.14.0 // indirect
sigs.k8s.io/kustomize/cmd/config v0.11.3 // indirect
sigs.k8s.io/kustomize/kyaml v0.14.3 // indirect
sigs.k8s.io/kustomize/api v0.15.0 // indirect
sigs.k8s.io/kustomize/cmd/config v0.12.0 // indirect
sigs.k8s.io/kustomize/kyaml v0.15.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
99 changes: 56 additions & 43 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion internal/resource/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ var _ = Describe("StatefulSet", func() {
It("updates Prometheus port", func() {
stsBuilder.Instance.Spec.TLS.SecretName = "tls-secret"
Expect(stsBuilder.Update(statefulSet)).To(Succeed())
expectedPodAnnotations := make(map[string]string, 0)
expectedPodAnnotations := make(map[string]string)
Expect(statefulSet.Spec.Template.Annotations).To(Equal(expectedPodAnnotations))
})
})
Expand Down
32 changes: 21 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"flag"
"fmt"
"os"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -100,8 +101,10 @@ func main() {
}

options := ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Scheme: scheme,
Metrics: server.Options{
BindAddress: metricsAddr,
},
LeaderElection: true,
LeaderElectionNamespace: operatorNamespace,
LeaderElectionID: "rabbitmq-cluster-operator-leader-election",
Expand All @@ -111,11 +114,17 @@ func main() {
if operatorScopeNamespace != "" {
if strings.Contains(operatorScopeNamespace, ",") {
namespaces := strings.Split(operatorScopeNamespace, ",")
options.Cache.Namespaces = namespaces
// https://github.com/kubernetes-sigs/controller-runtime/blob/main/designs/cache_options.md#only-cache-namespaced-objects-in-the-foo-and-bar-namespace
// Sometimes I wish that controller-runtime graduated to 1.x
// This changed in 0.15, and again in 0.16 🤦
options.Cache.DefaultNamespaces = make(map[string]cache.Config)
for _, namespace := range namespaces {
options.Cache.DefaultNamespaces[namespace] = cache.Config{}
}
log.Info("limiting watch to specific namespaces for RabbitMQ resources", "namespaces", namespaces)
} else {
options.Cache = cache.Options{
Namespaces: []string{operatorScopeNamespace},
DefaultNamespaces: map[string]cache.Config{operatorScopeNamespace: {}},
}
log.Info("limiting watch to one namespace", "namespace", operatorScopeNamespace)
}
Expand All @@ -136,23 +145,24 @@ func main() {
options.RetryPeriod = &retryPeriod
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), options)
if err != nil {
log.Error(err, "unable to start manager")
os.Exit(1)
}

if enableDebugPprof, ok := os.LookupEnv("ENABLE_DEBUG_PPROF"); ok {
pprofEnabled, err := strconv.ParseBool(enableDebugPprof)
if err == nil && pprofEnabled {
mgr, err = profiling.AddDebugPprofEndpoints(mgr)
o, err := profiling.AddDebugPprofEndpoints(&options)
if err != nil {
log.Error(err, "unable to add debug endpoints to manager")
os.Exit(1)
}
options = *o
}
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), options)
if err != nil {
log.Error(err, "unable to start manager")
os.Exit(1)
}

clusterConfig := config.GetConfigOrDie()

err = (&controllers.RabbitmqClusterReconciler{
Expand Down
12 changes: 6 additions & 6 deletions pkg/profiling/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
)

func AddDebugPprofEndpoints(mgr ctrl.Manager) (ctrl.Manager, error) {
func AddDebugPprofEndpoints(managerOpts *ctrl.Options) (*ctrl.Options, error) {
pprofEndpoints := map[string]http.HandlerFunc{
"/debug/pprof": http.HandlerFunc(pprof.Index),
"/debug/pprof/allocs": http.HandlerFunc(pprof.Index),
Expand All @@ -20,11 +20,11 @@ func AddDebugPprofEndpoints(mgr ctrl.Manager) (ctrl.Manager, error) {
"/debug/pprof/threadcreate": http.HandlerFunc(pprof.Index),
"/debug/pprof/trace": http.HandlerFunc(pprof.Trace),
}
if managerOpts.Metrics.ExtraHandlers == nil {
managerOpts.Metrics.ExtraHandlers = make(map[string]http.Handler)
}
for path, handler := range pprofEndpoints {
err := mgr.AddMetricsExtraHandler(path, handler)
if err != nil {
return mgr, err
}
managerOpts.Metrics.ExtraHandlers[path] = handler
}
return mgr, nil
return managerOpts, nil
}
8 changes: 5 additions & 3 deletions pkg/profiling/pprof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"net/http"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
)

var _ = Describe("Pprof", func() {
Expand All @@ -23,11 +24,12 @@ var _ = Describe("Pprof", func() {
BeforeEach(func() {
metricsEndpoint, err = getFreePort()
opts = ctrl.Options{
MetricsBindAddress: metricsEndpoint,
Metrics: server.Options{BindAddress: metricsEndpoint},
}
var o *ctrl.Options
o, err = profiling.AddDebugPprofEndpoints(&opts)
mgr, err = ctrl.NewManager(cfg, opts)
Expect(err).NotTo(HaveOccurred())
mgr, err = profiling.AddDebugPprofEndpoints(mgr)
opts = *o
Expect(err).NotTo(HaveOccurred())

})
Expand Down
18 changes: 15 additions & 3 deletions system_tests/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,21 @@ var _ = Describe("Operator", func() {
var flags []featureFlag
Expect(json.Unmarshal(output, &flags)).To(Succeed())
return flags
}, 30, 2).ShouldNot(ContainElement(MatchFields(IgnoreExtras, Fields{
"State": Not(Equal("enabled")),
})))
}, 30, 2).
Should(
Or(
ContainElement(
MatchFields(IgnoreExtras, Fields{
"State": BeEquivalentTo("enabled"),
}),
),
ContainElement(
MatchFields(IgnoreExtras, Fields{
"Name": Equal("khepri_db"),
"State": BeEquivalentTo("disabled"),
})), // temporary workaround since rabbitmq in main comes with Khepri disabled
),
)
})
})
})
Expand Down
Loading