Skip to content

Commit cf17e4d

Browse files
author
openshift-service-mesh-bot
committed
Automated merge
* upstream/main: Consolidate reconciler config fields into ReconcilerConfig (openshift-service-mesh#453) Refactor logs gather flow to support multiple clusters (openshift-service-mesh#452)
2 parents 02fe6ef + 881fff7 commit cf17e4d

22 files changed

+200
-135
lines changed

cmd/main.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ func main() {
4444
var metricsAddr string
4545
var probeAddr string
4646
var configFile string
47-
var resourceDirectory string
4847
var logAPIRequests bool
4948
var printVersion bool
5049
var leaderElectionEnabled bool
50+
var reconcilerCfg config.ReconcilerConfig
51+
5152
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
5253
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
5354
flag.StringVar(&configFile, "config-file", "/etc/sail-operator/config.properties", "Location of the config file, propagated by k8s downward APIs")
54-
flag.StringVar(&resourceDirectory, "resource-directory", "/var/lib/sail-operator/resources", "Where to find resources (e.g. charts)")
55+
flag.StringVar(&reconcilerCfg.ResourceDirectory, "resource-directory", "/var/lib/sail-operator/resources", "Where to find resources (e.g. charts)")
5556
flag.BoolVar(&logAPIRequests, "log-api-requests", false, "Whether to log each request sent to the Kubernetes API server")
5657
flag.BoolVar(&printVersion, "version", printVersion, "Prints version information and exits")
5758
flag.BoolVar(&leaderElectionEnabled, "leader-elect", true,
@@ -124,41 +125,40 @@ func main() {
124125

125126
chartManager := helm.NewChartManager(mgr.GetConfig(), os.Getenv("HELM_DRIVER"))
126127

127-
platform, err := config.DetectPlatform(mgr.GetConfig())
128+
reconcilerCfg.Platform, err = config.DetectPlatform(mgr.GetConfig())
128129
if err != nil {
129130
setupLog.Error(err, "unable to detect platform")
130131
os.Exit(1)
131132
}
132133

133-
var defaultProfile string
134-
if platform == config.PlatformOpenShift {
135-
defaultProfile = "openshift"
134+
if reconcilerCfg.Platform == config.PlatformOpenShift {
135+
reconcilerCfg.DefaultProfile = "openshift"
136136
} else {
137-
defaultProfile = "default"
137+
reconcilerCfg.DefaultProfile = "default"
138138
}
139139

140-
err = istio.NewReconciler(mgr.GetClient(), mgr.GetScheme(), resourceDirectory, platform, defaultProfile).
140+
err = istio.NewReconciler(reconcilerCfg, mgr.GetClient(), mgr.GetScheme()).
141141
SetupWithManager(mgr)
142142
if err != nil {
143143
setupLog.Error(err, "unable to create controller", "controller", "Istio")
144144
os.Exit(1)
145145
}
146146

147-
err = remoteistio.NewReconciler(mgr.GetClient(), mgr.GetScheme(), resourceDirectory, platform, defaultProfile).
147+
err = remoteistio.NewReconciler(reconcilerCfg, mgr.GetClient(), mgr.GetScheme()).
148148
SetupWithManager(mgr)
149149
if err != nil {
150150
setupLog.Error(err, "unable to create controller", "controller", "RemoteIstio")
151151
os.Exit(1)
152152
}
153153

154-
err = istiorevision.NewReconciler(mgr.GetClient(), mgr.GetScheme(), resourceDirectory, chartManager).
154+
err = istiorevision.NewReconciler(reconcilerCfg, mgr.GetClient(), mgr.GetScheme(), chartManager).
155155
SetupWithManager(mgr)
156156
if err != nil {
157157
setupLog.Error(err, "unable to create controller", "controller", "IstioRevision")
158158
os.Exit(1)
159159
}
160160

161-
err = istiocni.NewReconciler(mgr.GetClient(), mgr.GetScheme(), resourceDirectory, chartManager, platform, defaultProfile).
161+
err = istiocni.NewReconciler(reconcilerCfg, mgr.GetClient(), mgr.GetScheme(), chartManager).
162162
SetupWithManager(mgr)
163163
if err != nil {
164164
setupLog.Error(err, "unable to create controller", "controller", "IstioCNI")

controllers/istio/istio_controller.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,16 @@ import (
4646

4747
// Reconciler reconciles an Istio object
4848
type Reconciler struct {
49-
ResourceDirectory string
50-
Platform config.Platform
51-
DefaultProfile string
49+
Config config.ReconcilerConfig
5250
client.Client
5351
Scheme *runtime.Scheme
5452
}
5553

56-
func NewReconciler(client client.Client, scheme *runtime.Scheme, resourceDir string, platform config.Platform, defaultProfile string) *Reconciler {
54+
func NewReconciler(cfg config.ReconcilerConfig, client client.Client, scheme *runtime.Scheme) *Reconciler {
5755
return &Reconciler{
58-
ResourceDirectory: resourceDir,
59-
Platform: platform,
60-
DefaultProfile: defaultProfile,
61-
Client: client,
62-
Scheme: scheme,
56+
Config: cfg,
57+
Client: client,
58+
Scheme: scheme,
6359
}
6460
}
6561

@@ -111,8 +107,8 @@ func validate(istio *v1alpha1.Istio) error {
111107
func (r *Reconciler) reconcileActiveRevision(ctx context.Context, istio *v1alpha1.Istio) error {
112108
values, err := revision.ComputeValues(
113109
istio.Spec.Values, istio.Spec.Namespace, istio.Spec.Version,
114-
r.Platform, r.DefaultProfile, istio.Spec.Profile,
115-
r.ResourceDirectory, getActiveRevisionName(istio))
110+
r.Config.Platform, r.Config.DefaultProfile, istio.Spec.Profile,
111+
r.Config.ResourceDirectory, getActiveRevisionName(istio))
116112
if err != nil {
117113
return err
118114
}

controllers/istio/istio_controller_test.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var (
5151
)
5252

5353
func TestReconcile(t *testing.T) {
54-
resourceDir := t.TempDir()
54+
cfg := newReconcilerTestConfig(t)
5555

5656
t.Run("returns error when Istio version not set", func(t *testing.T) {
5757
istio := &v1alpha1.Istio{
@@ -61,7 +61,7 @@ func TestReconcile(t *testing.T) {
6161
cl := newFakeClientBuilder().
6262
WithObjects(istio).
6363
Build()
64-
reconciler := NewReconciler(cl, scheme.Scheme, resourceDir, config.PlatformKubernetes, "")
64+
reconciler := NewReconciler(cfg, cl, scheme.Scheme)
6565

6666
_, err := reconciler.Reconcile(ctx, istio)
6767
if err == nil {
@@ -97,7 +97,9 @@ func TestReconcile(t *testing.T) {
9797
WithStatusSubresource(&v1alpha1.Istio{}).
9898
WithObjects(istio).
9999
Build()
100-
reconciler := NewReconciler(cl, scheme.Scheme, resourceDir, config.PlatformKubernetes, "invalid-profile")
100+
cfg := newReconcilerTestConfig(t)
101+
cfg.DefaultProfile = "invalid-profile"
102+
reconciler := NewReconciler(cfg, cl, scheme.Scheme)
101103

102104
_, err := reconciler.Reconcile(ctx, istio)
103105
if err == nil {
@@ -137,7 +139,7 @@ func TestReconcile(t *testing.T) {
137139
},
138140
}).
139141
Build()
140-
reconciler := NewReconciler(cl, scheme.Scheme, resourceDir, config.PlatformKubernetes, "")
142+
reconciler := NewReconciler(cfg, cl, scheme.Scheme)
141143

142144
_, err := reconciler.Reconcile(ctx, istio)
143145
if err == nil {
@@ -222,7 +224,7 @@ func TestValidate(t *testing.T) {
222224
}
223225

224226
func TestDetermineStatus(t *testing.T) {
225-
resourceDir := t.TempDir()
227+
cfg := newReconcilerTestConfig(t)
226228

227229
generation := int64(100)
228230

@@ -533,7 +535,7 @@ func TestDetermineStatus(t *testing.T) {
533535
WithObjects(initObjs...).
534536
WithInterceptorFuncs(interceptorFuncs).
535537
Build()
536-
reconciler := NewReconciler(cl, scheme.Scheme, resourceDir, config.PlatformKubernetes, "")
538+
reconciler := NewReconciler(cfg, cl, scheme.Scheme)
537539

538540
status, err := reconciler.determineStatus(ctx, istio, tc.reconciliationErr)
539541
if (err != nil) != tc.wantErr {
@@ -548,7 +550,7 @@ func TestDetermineStatus(t *testing.T) {
548550
}
549551

550552
func TestUpdateStatus(t *testing.T) {
551-
resourceDir := t.TempDir()
553+
cfg := newReconcilerTestConfig(t)
552554

553555
generation := int64(100)
554556
oneMinuteAgo := testtime.OneMinuteAgo()
@@ -734,7 +736,7 @@ func TestUpdateStatus(t *testing.T) {
734736
WithObjects(initObjs...).
735737
WithInterceptorFuncs(interceptorFuncs).
736738
Build()
737-
reconciler := NewReconciler(cl, scheme.Scheme, resourceDir, config.PlatformKubernetes, "")
739+
reconciler := NewReconciler(cfg, cl, scheme.Scheme)
738740

739741
err := reconciler.updateStatus(ctx, istio, tc.reconciliationErr)
740742
if (err != nil) != tc.wantErr {
@@ -915,3 +917,11 @@ func noWrites(t *testing.T) interceptor.Funcs {
915917
},
916918
}
917919
}
920+
921+
func newReconcilerTestConfig(t *testing.T) config.ReconcilerConfig {
922+
return config.ReconcilerConfig{
923+
ResourceDirectory: t.TempDir(),
924+
Platform: config.PlatformKubernetes,
925+
DefaultProfile: "",
926+
}
927+
}

controllers/istiocni/istiocni_controller.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,18 @@ const (
5656

5757
// Reconciler reconciles an IstioCNI object
5858
type Reconciler struct {
59-
ResourceDirectory string
60-
Platform config.Platform
61-
DefaultProfile string
6259
client.Client
60+
Config config.ReconcilerConfig
6361
Scheme *runtime.Scheme
6462
ChartManager *helm.ChartManager
6563
}
6664

67-
func NewReconciler(
68-
client client.Client, scheme *runtime.Scheme, resourceDir string, chartManager *helm.ChartManager, platform config.Platform, defaultProfile string,
69-
) *Reconciler {
65+
func NewReconciler(cfg config.ReconcilerConfig, client client.Client, scheme *runtime.Scheme, chartManager *helm.ChartManager) *Reconciler {
7066
return &Reconciler{
71-
ResourceDirectory: resourceDir,
72-
Platform: platform,
73-
DefaultProfile: defaultProfile,
74-
Client: client,
75-
Scheme: scheme,
76-
ChartManager: chartManager,
67+
Config: cfg,
68+
Client: client,
69+
Scheme: scheme,
70+
ChartManager: chartManager,
7771
}
7872
}
7973

@@ -153,7 +147,7 @@ func (r *Reconciler) installHelmChart(ctx context.Context, cni *v1alpha1.IstioCN
153147

154148
// apply userValues on top of defaultValues from profiles
155149
mergedHelmValues, err := istiovalues.ApplyProfilesAndPlatform(
156-
r.ResourceDirectory, cni.Spec.Version, r.Platform, r.DefaultProfile, cni.Spec.Profile, helm.FromValues(userValues))
150+
r.Config.ResourceDirectory, cni.Spec.Version, r.Config.Platform, r.Config.DefaultProfile, cni.Spec.Profile, helm.FromValues(userValues))
157151
if err != nil {
158152
return fmt.Errorf("failed to apply profile: %w", err)
159153
}
@@ -166,7 +160,7 @@ func (r *Reconciler) installHelmChart(ctx context.Context, cni *v1alpha1.IstioCN
166160
}
167161

168162
func (r *Reconciler) getChartDir(cni *v1alpha1.IstioCNI) string {
169-
return path.Join(r.ResourceDirectory, cni.Spec.Version, "charts", cniChartName)
163+
return path.Join(r.Config.ResourceDirectory, cni.Spec.Version, "charts", cniChartName)
170164
}
171165

172166
func applyImageDigests(cni *v1alpha1.IstioCNI, values *v1alpha1.CNIValues, config config.OperatorConfig) *v1alpha1.CNIValues {

controllers/istiocni/istiocni_controller_test.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import (
3636
)
3737

3838
func TestValidate(t *testing.T) {
39+
cfg := newReconcilerTestConfig(t)
40+
3941
ns := &corev1.Namespace{
4042
ObjectMeta: metav1.ObjectMeta{
4143
Name: "istio-cni",
@@ -107,7 +109,7 @@ func TestValidate(t *testing.T) {
107109
t.Run(tc.name, func(t *testing.T) {
108110
g := NewWithT(t)
109111
cl := fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(tc.objects...).Build()
110-
r := NewReconciler(cl, scheme.Scheme, "", nil, config.PlatformKubernetes, "")
112+
r := NewReconciler(cfg, cl, scheme.Scheme, nil)
111113

112114
err := r.validate(context.TODO(), tc.cni)
113115
if tc.expectErr == "" {
@@ -177,7 +179,7 @@ func newCondition(condType v1alpha1.IstioCNIConditionType, status metav1.Conditi
177179
}
178180

179181
func TestDetermineReadyCondition(t *testing.T) {
180-
resourceDir := t.TempDir()
182+
cfg := newReconcilerTestConfig(t)
181183

182184
testCases := []struct {
183185
name string
@@ -282,7 +284,7 @@ func TestDetermineReadyCondition(t *testing.T) {
282284

283285
cl := fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(tt.clientObjects...).WithInterceptorFuncs(tt.interceptors).Build()
284286

285-
r := NewReconciler(cl, scheme.Scheme, resourceDir, nil, config.PlatformKubernetes, "")
287+
r := NewReconciler(cfg, cl, scheme.Scheme, nil)
286288

287289
cni := &v1alpha1.IstioCNI{
288290
ObjectMeta: metav1.ObjectMeta{
@@ -447,6 +449,8 @@ func TestApplyImageDigests(t *testing.T) {
447449
}
448450

449451
func TestDetermineStatus(t *testing.T) {
452+
cfg := newReconcilerTestConfig(t)
453+
450454
tests := []struct {
451455
name string
452456
reconcileErr error
@@ -462,9 +466,8 @@ func TestDetermineStatus(t *testing.T) {
462466
}
463467

464468
ctx := context.TODO()
465-
resourceDir := t.TempDir()
466469
cl := fake.NewClientBuilder().WithScheme(scheme.Scheme).Build()
467-
r := NewReconciler(cl, scheme.Scheme, resourceDir, nil, config.PlatformKubernetes, "")
470+
r := NewReconciler(cfg, cl, scheme.Scheme, nil)
468471

469472
for _, tt := range tests {
470473
t.Run(tt.name, func(t *testing.T) {
@@ -497,3 +500,11 @@ func normalize(condition v1alpha1.IstioCNICondition) v1alpha1.IstioCNICondition
497500
condition.LastTransitionTime = metav1.Time{}
498501
return condition
499502
}
503+
504+
func newReconcilerTestConfig(t *testing.T) config.ReconcilerConfig {
505+
return config.ReconcilerConfig{
506+
ResourceDirectory: t.TempDir(),
507+
Platform: config.PlatformKubernetes,
508+
DefaultProfile: "",
509+
}
510+
}

controllers/istiorevision/istiorevision_controller.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/go-logr/logr"
2626
"github.com/istio-ecosystem/sail-operator/api/v1alpha1"
27+
"github.com/istio-ecosystem/sail-operator/pkg/config"
2728
"github.com/istio-ecosystem/sail-operator/pkg/constants"
2829
"github.com/istio-ecosystem/sail-operator/pkg/enqueuelogger"
2930
"github.com/istio-ecosystem/sail-operator/pkg/errlist"
@@ -67,17 +68,17 @@ const (
6768
// Reconciler reconciles an IstioRevision object
6869
type Reconciler struct {
6970
client.Client
70-
Scheme *runtime.Scheme
71-
ResourceDirectory string
72-
ChartManager *helm.ChartManager
71+
Config config.ReconcilerConfig
72+
Scheme *runtime.Scheme
73+
ChartManager *helm.ChartManager
7374
}
7475

75-
func NewReconciler(client client.Client, scheme *runtime.Scheme, resourceDir string, chartManager *helm.ChartManager) *Reconciler {
76+
func NewReconciler(cfg config.ReconcilerConfig, client client.Client, scheme *runtime.Scheme, chartManager *helm.ChartManager) *Reconciler {
7677
return &Reconciler{
77-
Client: client,
78-
Scheme: scheme,
79-
ResourceDirectory: resourceDir,
80-
ChartManager: chartManager,
78+
Config: cfg,
79+
Client: client,
80+
Scheme: scheme,
81+
ChartManager: chartManager,
8182
}
8283
}
8384

@@ -181,7 +182,7 @@ func getReleaseName(rev *v1alpha1.IstioRevision) string {
181182
}
182183

183184
func (r *Reconciler) getChartDir(rev *v1alpha1.IstioRevision) string {
184-
return path.Join(r.ResourceDirectory, rev.Spec.Version, "charts", getChartName(rev))
185+
return path.Join(r.Config.ResourceDirectory, rev.Spec.Version, "charts", getChartName(rev))
185186
}
186187

187188
func getChartName(rev *v1alpha1.IstioRevision) string {

0 commit comments

Comments
 (0)