Skip to content

Commit 1a2ffd2

Browse files
committed
Replace deprecated method use for CR v0.15.0
This change replaces deprecated method usage with the new standards defined by controller-runtime v0.15.0. The changes are noted in the release notes: https://github.com/kubernetes-sigs/controller-runtime/releases/tag/v0.15.0 Specifically we are changing: 1. Usage of options.Namespace replaced by options.Cache.Namespaces 2. Usage of MultiNamespacedCacheBuilder replaced by options.Cache{Namespaces} struct. 3. wait.ErrWaitTimeout replaced by wait.Interrupted(err) Signed-off-by: Brendan Shephard <[email protected]>
1 parent 3e140c4 commit 1a2ffd2

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

internal/cmd/helm-operator/run/cmd.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,20 @@ func run(cmd *cobra.Command, f *flags.Flags) {
149149
log.V(1).Info(fmt.Sprintf("Setting namespace with value in %s", helmmgr.WatchNamespaceEnvVar))
150150
if namespace == metav1.NamespaceAll {
151151
log.Info("Watching all namespaces.")
152-
options.Namespace = metav1.NamespaceAll
152+
options.Cache.Namespaces = []string{metav1.NamespaceAll}
153153
} else {
154154
if strings.Contains(namespace, ",") {
155155
log.Info("Watching multiple namespaces.")
156-
options.NewCache = cache.MultiNamespacedCacheBuilder(strings.Split(namespace, ","))
156+
options.Cache = cache.Options{Namespaces: strings.Split(namespace, ",")}
157157
} else {
158158
log.Info("Watching single namespace.")
159-
options.Namespace = namespace
159+
options.Cache.Namespaces = []string{namespace}
160160
}
161161
}
162-
} else if options.Namespace == "" {
162+
} else if len(options.Cache.Namespaces) == 0 {
163163
log.Info(fmt.Sprintf("Watch namespaces not configured by environment variable %s or file. "+
164164
"Watching all namespaces.", helmmgr.WatchNamespaceEnvVar))
165-
options.Namespace = metav1.NamespaceAll
165+
options.Cache.Namespaces = []string{metav1.NamespaceAll}
166166
}
167167

168168
mgr, err := manager.New(cfg, options)

internal/sdk/controllerutil/controllerutil_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package controllerutil_test
1818

1919
import (
2020
"context"
21+
"fmt"
2122

2223
. "github.com/onsi/ginkgo/v2"
2324
. "github.com/onsi/gomega"
@@ -62,7 +63,7 @@ var _ = Describe("Controllerutil", func() {
6263

6364
It("should be cancellable", func() {
6465
cancel()
65-
Expect(WaitForDeletion(ctx, client, pod)).To(MatchError(wait.ErrWaitTimeout))
66+
Expect(WaitForDeletion(ctx, client, pod)).To(MatchError(wait.Interrupted(fmt.Errorf("timed out waiting for the condition"))))
6667
})
6768

6869
It("should succeed after pod is deleted", func() {

pkg/manager/namespace.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ func ConfigureWatchNamespaces(options *manager.Options, log logr.Logger) {
3535
if len(namespaces) != 0 {
3636
log.Info("watching namespaces", "namespaces", namespaces)
3737
if len(namespaces) > 1 {
38-
options.NewCache = cache.MultiNamespacedCacheBuilder(namespaces)
38+
options.Cache = cache.Options{Namespaces: namespaces}
3939
} else {
40-
options.Namespace = namespaces[0]
40+
options.Cache = cache.Options{Namespaces: []string{}}
4141
}
4242
return
4343
}
4444
log.Info("watching all namespaces")
45-
options.Namespace = v1.NamespaceAll
45+
options.Cache.Namespaces = []string{v1.NamespaceAll}
4646
}
4747

4848
func lookupEnv() []string {

pkg/manager/namespace_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ var _ = Describe("ConfigureWatchNamespaces", func() {
4949

5050
It("should watch all namespaces when no env set", func() {
5151
ConfigureWatchNamespaces(&opts, log)
52-
Expect(opts.Namespace).To(Equal(""))
52+
Expect(opts.Cache.Namespaces).To(Equal(""))
5353
Expect(opts.NewCache).To(BeNil())
5454
})
5555

5656
It("should watch all namespaces when WATCH_NAMESPACE is empty", func() {
5757
Expect(os.Setenv(WatchNamespaceEnvVar, ""))
5858
ConfigureWatchNamespaces(&opts, log)
59-
Expect(opts.Namespace).To(Equal(""))
59+
Expect(opts.Cache.Namespaces).To(Equal(""))
6060
Expect(opts.NewCache).To(BeNil())
6161
})
6262

6363
It("should watch one namespace when WATCH_NAMESPACE is has one namespace", func() {
6464
Expect(os.Setenv(WatchNamespaceEnvVar, "watch"))
6565
ConfigureWatchNamespaces(&opts, log)
66-
Expect(opts.Namespace).To(Equal("watch"))
66+
Expect(opts.Cache.Namespaces).To(Equal("watch"))
6767
Expect(opts.NewCache).To(BeNil())
6868
})
6969

@@ -81,7 +81,7 @@ var _ = Describe("ConfigureWatchNamespaces", func() {
8181
ConfigureWatchNamespaces(&opts, log)
8282

8383
By("checking that a single-namespace watch is not configured")
84-
Expect(opts.Namespace).To(Equal(""))
84+
Expect(opts.Cache.Namespaces).To(Equal(""))
8585

8686
By("using the options NewCache function to create a cache")
8787
c, err := opts.NewCache(cfg, cache.Options{})

0 commit comments

Comments
 (0)