Skip to content

Commit f095f4d

Browse files
authored
CSPL-3898 Fixing int-helm tests failing after SDK upgrade (#1544)
1 parent 32fcae0 commit f095f4d

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

.github/workflows/helm-test-workflow.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
- develop
66
- main
77
- feature**
8+
workflow_dispatch:
89
jobs:
910
build-operator-image:
1011
runs-on: ubuntu-latest

cmd/main.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ package main
1919
import (
2020
"flag"
2121
"fmt"
22+
"os"
23+
"time"
24+
2225
intController "github.com/splunk/splunk-operator/internal/controller"
2326
"github.com/splunk/splunk-operator/internal/controller/debug"
24-
"os"
27+
"github.com/splunk/splunk-operator/pkg/config"
2528
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
26-
"time"
2729

2830
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
2931
// to ensure that exec-entrypoint and run can make use of them.
@@ -108,7 +110,7 @@ func main() {
108110
// Logging setup
109111
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
110112

111-
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
113+
baseOptions := ctrl.Options{
112114
Metrics: metricsserver.Options{
113115
BindAddress: metricsAddr,
114116
FilterProvider: filters.WithAuthenticationAndAuthorization,
@@ -119,7 +121,12 @@ func main() {
119121
LeaderElectionID: "270bec8c.splunk.com",
120122
LeaseDuration: &leaseDuration,
121123
RenewDeadline: &renewDeadline,
122-
})
124+
}
125+
126+
// Apply namespace-specific configuration
127+
managerOptions := config.ManagerOptionsWithNamespaces(setupLog, baseOptions)
128+
129+
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), managerOptions)
123130

124131
if err != nil {
125132
setupLog.Error(err, "unable to start manager")

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,4 @@ require (
141141
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
142142
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
143143
sigs.k8s.io/yaml v1.4.0 // indirect
144-
)
144+
)

go.sum

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,4 +492,4 @@ sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h6
492492
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=
493493
sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08=
494494
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
495-
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
495+
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=

pkg/config/config.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,26 @@ func GetWatchNamespaces() []string {
4848

4949
// ManagerOptionsWithNamespaces returns an updated Options with namespaces information.
5050
func ManagerOptionsWithNamespaces(logger logr.Logger, opt ctrl.Options) ctrl.Options {
51+
opts := cache.Options{}
5152
namespaces := GetWatchNamespaces()
5253
switch {
53-
case len(namespaces) == 0:
54-
logger.Info("Manager will watch and manage resources in all namespaces")
55-
return ctrl.Options{Cache: cache.Options{DefaultNamespaces: map[string]cache.Config{
56-
cache.AllNamespaces: {},
57-
}}}
5854
case len(namespaces) == 1:
5955
logger.Info("Manager will be watching namespace", "namespace", namespaces[0])
60-
return ctrl.Options{Cache: cache.Options{DefaultNamespaces: map[string]cache.Config{
56+
opts = cache.Options{DefaultNamespaces: map[string]cache.Config{
6157
namespaces[0]: {},
62-
}}}
58+
}}
6359
case len(namespaces) > 1:
6460
nsMap := map[string]cache.Config{}
6561
for _, ns := range namespaces {
6662
nsMap[ns] = cache.Config{}
6763
}
6864
logger.Info("Manager will be watching multiple namespaces", "namespaces", namespaces)
69-
return ctrl.Options{Cache: cache.Options{DefaultNamespaces: nsMap}}
65+
opts = cache.Options{DefaultNamespaces: nsMap}
7066
}
7167

68+
// By default, the cache will watch and list requested objects in all namespaces.
69+
70+
opt.Cache = opts
71+
7272
return opt
7373
}

0 commit comments

Comments
 (0)