Skip to content

Commit 3969b9b

Browse files
authored
feat: support helm dryrun=server (operator-framework#6691)
* feat: support helm dryrun=server Signed-off-by: Sam Wang (holyspectral) <[email protected]> * fix: CI errors after test-sanity Signed-off-by: Sam Wang (holyspectral) <[email protected]> * docs: update testdata/v3/memcached-operator to v4 Signed-off-by: Sam Wang (holyspectral) <[email protected]> --------- Signed-off-by: Sam Wang (holyspectral) <[email protected]>
1 parent aca3a2c commit 3969b9b

File tree

18 files changed

+53
-19
lines changed

18 files changed

+53
-19
lines changed

.cncf-maintainers

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
approvers:
2+
- acornett21
23
- anik120
34
- everettraven
45
- fabianvf
@@ -10,6 +11,7 @@ approvers:
1011
- theishshah
1112
- varshaprasad96
1213
reviewers:
14+
- acornett21
1315
- anik120
1416
- everettraven
1517
- fabianvf

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ func run(cmd *cobra.Command, f *flags.Flags) {
203203
SuppressOverrideValues: f.SuppressOverrideValues,
204204
MaxConcurrentReconciles: f.MaxConcurrentReconciles,
205205
Selector: w.Selector,
206+
DryRunOption: w.DryRunOption,
206207
})
207208
if err != nil {
208209
log.Error(err, "Failed to add manager factory to controller.")

internal/helm/controller/controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type WatchOptions struct {
5252
SuppressOverrideValues bool
5353
MaxConcurrentReconciles int
5454
Selector metav1.LabelSelector
55+
DryRunOption string
5556
}
5657

5758
// Add creates a new helm operator controller and adds it to the manager
@@ -66,6 +67,7 @@ func Add(mgr manager.Manager, options WatchOptions) error {
6667
ReconcilePeriod: options.ReconcilePeriod,
6768
OverrideValues: options.OverrideValues,
6869
SuppressOverrideValues: options.SuppressOverrideValues,
70+
DryRunOption: options.DryRunOption,
6971
}
7072

7173
c, err := controller.New(controllerName, mgr, controller.Options{

internal/helm/controller/reconcile.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type HelmOperatorReconciler struct {
5555
OverrideValues map[string]string
5656
SuppressOverrideValues bool
5757
releaseHook ReleaseHookFunc
58+
DryRunOption string
5859
}
5960

6061
const (
@@ -96,7 +97,7 @@ func (r HelmOperatorReconciler) Reconcile(ctx context.Context, request reconcile
9697
return reconcile.Result{}, err
9798
}
9899

99-
manager, err := r.ManagerFactory.NewManager(o, r.OverrideValues)
100+
manager, err := r.ManagerFactory.NewManager(o, r.OverrideValues, r.DryRunOption)
100101
if err != nil {
101102
log.Error(err, "Failed to get release manager")
102103
return reconcile.Result{}, err

internal/helm/release/manager.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ type manager struct {
7575
isUpgradeRequired bool
7676
deployedRelease *rpb.Release
7777
chart *cpb.Chart
78+
79+
dryRunOption string
7880
}
7981

8082
type InstallOption func(*action.Install) error
@@ -159,6 +161,7 @@ func (m manager) getCandidateRelease(namespace, name string, chart *cpb.Chart,
159161
upgrade := action.NewUpgrade(m.actionConfig)
160162
upgrade.Namespace = namespace
161163
upgrade.DryRun = true
164+
upgrade.DryRunOption = m.dryRunOption
162165
return upgrade.Run(name, chart, values)
163166
}
164167

internal/helm/release/manager_factory.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
// improves decoupling between reconciliation logic and the Helm backend
3434
// components used to manage releases.
3535
type ManagerFactory interface {
36-
NewManager(r *unstructured.Unstructured, overrideValues map[string]string) (Manager, error)
36+
NewManager(r *unstructured.Unstructured, overrideValues map[string]string, dryRunOption string) (Manager, error)
3737
}
3838

3939
type managerFactory struct {
@@ -47,7 +47,7 @@ func NewManagerFactory(mgr crmanager.Manager, acg client.ActionConfigGetter, cha
4747
return &managerFactory{mgr, acg, chartDir}
4848
}
4949

50-
func (f managerFactory) NewManager(cr *unstructured.Unstructured, overrideValues map[string]string) (Manager, error) {
50+
func (f managerFactory) NewManager(cr *unstructured.Unstructured, overrideValues map[string]string, dryRunOption string) (Manager, error) {
5151
actionConfig, err := f.acg.ActionConfigFor(cr)
5252
if err != nil {
5353
return nil, fmt.Errorf("failed to get helm action config: %w", err)
@@ -86,9 +86,10 @@ func (f managerFactory) NewManager(cr *unstructured.Unstructured, overrideValues
8686
releaseName: releaseName,
8787
namespace: cr.GetNamespace(),
8888

89-
chart: crChart,
90-
values: values,
91-
status: types.StatusFor(cr),
89+
chart: crChart,
90+
values: values,
91+
status: types.StatusFor(cr),
92+
dryRunOption: dryRunOption,
9293
}, nil
9394
}
9495

internal/helm/watches/watches.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Watch struct {
4040
OverrideValues map[string]string `json:"overrideValues,omitempty"`
4141
Selector metav1.LabelSelector `json:"selector"`
4242
ReconcilePeriod metav1.Duration `json:"reconcilePeriod,omitempty"`
43+
DryRunOption string `json:"dryRunOption,omitempty"`
4344
}
4445

4546
// UnmarshalYAML unmarshals an individual watch from the Helm watches.yaml file

internal/helm/watches/watches_test.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,30 @@ func TestLoadReader(t *testing.T) {
101101
},
102102
expectErr: false,
103103
},
104-
104+
{
105+
name: "valid with dry run option",
106+
data: `---
107+
- group: mygroup
108+
version: v1alpha1
109+
kind: MyKind
110+
chart: ../../../internal/plugins/helm/v1/chartutil/testdata/test-chart
111+
watchDependentResources: false
112+
overrideValues:
113+
key: $MY_VALUE
114+
dryRunOption: server
115+
`,
116+
env: map[string]string{"MY_VALUE": "value"},
117+
expectWatches: []Watch{
118+
{
119+
GroupVersionKind: schema.GroupVersionKind{Group: "mygroup", Version: "v1alpha1", Kind: "MyKind"},
120+
ChartDir: "../../../internal/plugins/helm/v1/chartutil/testdata/test-chart",
121+
WatchDependentResources: &falseVal,
122+
OverrideValues: map[string]string{"key": "value"},
123+
DryRunOption: "server",
124+
},
125+
},
126+
expectErr: false,
127+
},
105128
{
106129
name: "invalid with override template expansion",
107130
data: `---

testdata/go/v4/memcached-operator/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ endif
4848

4949
# Set the Operator SDK version to use. By default, what is installed on the system is used.
5050
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
51-
OPERATOR_SDK_VERSION ?= v1.33.0
51+
OPERATOR_SDK_VERSION ?= v1.34.0
5252

5353
# Image URL to use all building/pushing image targets
5454
IMG ?= controller:latest

testdata/go/v4/monitoring/memcached-operator/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ endif
4848

4949
# Set the Operator SDK version to use. By default, what is installed on the system is used.
5050
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
51-
OPERATOR_SDK_VERSION ?= v1.33.0
51+
OPERATOR_SDK_VERSION ?= v1.34.0
5252

5353
# Image URL to use all building/pushing image targets
5454
IMG ?= controller:latest

testdata/helm/memcached-operator/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ endif
4848

4949
# Set the Operator SDK version to use. By default, what is installed on the system is used.
5050
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
51-
OPERATOR_SDK_VERSION ?= v1.33.0
51+
OPERATOR_SDK_VERSION ?= v1.34.0
5252

5353
# Image URL to use all building/pushing image targets
5454
IMG ?= controller:latest

website/content/en/docs/best-practices/common-recommendation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,4 @@ spec:
105105
[k8s-manage-resources]: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
106106
[best practices]: https://olm.operatorframework.io/docs/concepts/olm-architecture/dependency-resolution/
107107
[Dependency Resolution]: /docs/best-practices/best-practices
108-
[sample]: https://github.com/operator-framework/operator-sdk/tree/master/testdata/go/v3/memcached-operator
108+
[sample]: https://github.com/operator-framework/operator-sdk/tree/master/testdata/go/v4/memcached-operator

website/content/en/docs/best-practices/pod-security-standards.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ the Operator bundle generated with the target is built from the manifests under
134134
the layout of your operator built with Operator-SDK see [Project Layout][project-layout].
135135

136136
To check an example of a CSV which complies with the [restricted][restricted] policy, see the Golang sample
137-
under the [testdata/go/v3/memcached-operator/bundle/manifests/memcached-operator.clusterserviceversion.yaml](https://github.com/operator-framework/operator-sdk/blob/master/testdata/go/v3/memcached-operator/bundle/manifests/memcached-operator.clusterserviceversion.yaml)
137+
under the [testdata/go/v4/memcached-operator/bundle/manifests/memcached-operator.clusterserviceversion.yaml](https://github.com/operator-framework/operator-sdk/blob/master/testdata/go/v4/memcached-operator/bundle/manifests/memcached-operator.clusterserviceversion.yaml)
138138

139139
### How can I verify my manifest?
140140

@@ -419,5 +419,5 @@ Therefore, if you want your workloads running in namespaces labeled to enforce r
419419
[restricted]: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
420420
[security-standards]: https://kubernetes.io/docs/concepts/security/pod-security-standards/
421421
[psachecker]: https://github.com/stlaz/psachecker
422-
[sample]: https://github.com/operator-framework/operator-sdk/tree/master/testdata/go/v3/memcached-operator
423-
[docker-good-practices-doc]: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
422+
[sample]: https://github.com/operator-framework/operator-sdk/tree/master/testdata/go/v4/memcached-operator
423+
[docker-good-practices-doc]: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user

website/content/en/docs/building-operators/golang/migration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ For further steps regarding the deployment of the operator, creation of custom r
418418
[install-guide]: /docs/building-operators/ansible/installation
419419
[image-reg-config]:/docs/olm-integration/cli-overview#private-bundle-and-catalog-image-registries
420420
[metrics]: https://book.kubebuilder.io/reference/metrics.html?highlight=metr#metrics
421-
[memcached_controller]: https://github.com/operator-framework/operator-sdk/tree/master/testdata/go/v3/memcached-operator
421+
[memcached_controller]: https://github.com/operator-framework/operator-sdk/tree/master/testdata/go/v4/memcached-operator
422422
[rbac_markers]: https://book.kubebuilder.io/reference/markers/rbac.html
423423
[kube-auth-proxy]: https://github.com/brancz/kube-rbac-proxy
424424
[markers]: https://book.kubebuilder.io/reference/markers.html?highlight=markers#marker-syntax

website/content/en/docs/building-operators/golang/references/client.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ func labelsForApp(name string) map[string]string {
580580
}
581581
```
582582

583-
[memcached-testdata]:https://github.com/operator-framework/operator-sdk/tree/master/testdata/go/v3/memcached-operator
583+
[memcached-testdata]:https://github.com/operator-framework/operator-sdk/tree/master/testdata/go/v4/memcached-operator
584584
[repo-controller-runtime]:https://github.com/kubernetes-sigs/controller-runtime
585585
[doc-client]:https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/client#Client
586586
[doc-split-client]:https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/client#DelegatingClient

website/content/en/docs/building-operators/golang/testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ To implement application-specific tests, the SDK's test harness, [scorecard][sco
5454
[scorecard]: /docs/testing-operators/scorecard/
5555
[gomega]: https://onsi.github.io/gomega/
5656
[kuttl]: https://kuttl.dev/
57-
[sample]: https://github.com/operator-framework/operator-sdk/tree/master/testdata/go/v3/memcached-operator
57+
[sample]: https://github.com/operator-framework/operator-sdk/tree/master/testdata/go/v4/memcached-operator
5858
[molecule]: https://molecule.readthedocs.io/
5959
[molecule-tests]: /docs/building-operators/ansible/testing-guide
6060
[helm-chart-tests]: https://helm.sh/docs/topics/chart_tests/

website/content/en/docs/building-operators/golang/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ Next, check out the following:
543543
[legacy_CLI]:https://github.com/operator-framework/operator-sdk/tree/v0.19.x/website/content/en/docs/cli
544544
[manager_go_doc]: https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/manager#Manager
545545
[markers]: https://book.kubebuilder.io/reference/markers.html
546-
[memcached_controller]: https://github.com/operator-framework/operator-sdk/blob/latest/testdata/go/v3/memcached-operator/controllers/memcached_controller.go
546+
[memcached_controller]: https://github.com/operator-framework/operator-sdk/blob/latest/testdata/go/v4/memcached-operator/internal/controller/memcached_controller.go
547547
[migration-guide]:/docs/building-operators/golang/migration
548548
[multi-namespaced-cache-builder]: https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/cache#MultiNamespacedCacheBuilder
549549
[multigroup-kubebuilder-doc]: https://book.kubebuilder.io/migration/multi-group.html

website/content/en/docs/testing-operators/scorecard/custom-tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ connection to invoke the Kube API.
311311
[basic_tests]: https://github.com/operator-framework/operator-sdk/blob/09c3aa14625965af9f22f513cd5c891471dbded2/internal/scorecard/tests/basic.go
312312
[config_yaml]: https://github.com/operator-framework/operator-sdk/blob/09c3aa14625965af9f22f513cd5c891471dbded2/internal/scorecard/testdata/bundle/tests/scorecard/config.yaml
313313
[scorecard_main_func]: https://github.com/operator-framework/operator-sdk/blob/09c3aa14625965af9f22f513cd5c891471dbded2/images/scorecard-test/main.go
314-
[custom_scorecard_repo]:https://github.com/operator-framework/operator-sdk/tree/master/testdata/go/v3/memcached-operator
314+
[custom_scorecard_repo]:https://github.com/operator-framework/operator-sdk/tree/master/testdata/go/v4/memcached-operator
315315
[user_doc]: /docs/testing-operators/scorecard/
316316
[scorecard_binary]: https://github.com/operator-framework/operator-sdk/blob/09c3aa14625965af9f22f513cd5c891471dbded2/images/custom-scorecard-tests/main.go
317317
[sample_makefile]: https://github.com/operator-framework/operator-sdk/blob/09c3aa14625965af9f22f513cd5c891471dbded2/Makefile

0 commit comments

Comments
 (0)