Skip to content

Commit 1d189d7

Browse files
joelanfordPer Goncalves da Silva
authored and
Per Goncalves da Silva
committed
helm: use chunking release driver in systemNamespace (operator-framework#1057)
Signed-off-by: Joe Lanford <[email protected]>
1 parent 7c6c816 commit 1d189d7

File tree

9 files changed

+292
-55
lines changed

9 files changed

+292
-55
lines changed

cmd/manager/main.go

+8-30
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ import (
3030
apiextensionsv1client "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
3131
k8slabels "k8s.io/apimachinery/pkg/labels"
3232
"k8s.io/apimachinery/pkg/selection"
33-
"k8s.io/apimachinery/pkg/types"
3433
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
3534
_ "k8s.io/client-go/plugin/pkg/client/auth"
36-
"k8s.io/client-go/rest"
3735
ctrl "sigs.k8s.io/controller-runtime"
3836
crcache "sigs.k8s.io/controller-runtime/pkg/cache"
3937
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -162,41 +160,21 @@ func main() {
162160
os.Exit(1)
163161
}
164162

165-
installNamespaceMapper := helmclient.ObjectToStringMapper(func(obj client.Object) (string, error) {
166-
ext := obj.(*ocv1alpha1.ClusterExtension)
167-
return ext.Spec.InstallNamespace, nil
168-
})
169163
coreClient, err := corev1client.NewForConfig(mgr.GetConfig())
170164
if err != nil {
171165
setupLog.Error(err, "unable to create core client")
172166
os.Exit(1)
173167
}
174168
tokenGetter := authentication.NewTokenGetter(coreClient, authentication.WithExpirationDuration(1*time.Hour))
175-
176-
restConfigMapper := func(ctx context.Context, o client.Object, c *rest.Config) (*rest.Config, error) {
177-
cExt, ok := o.(*ocv1alpha1.ClusterExtension)
178-
if !ok {
179-
return c, nil
180-
}
181-
namespacedName := types.NamespacedName{
182-
Name: cExt.Spec.ServiceAccount.Name,
183-
Namespace: cExt.Spec.InstallNamespace,
184-
}
185-
tempConfig := rest.AnonymousClientConfig(c)
186-
tempConfig.WrapTransport = func(rt http.RoundTripper) http.RoundTripper {
187-
return &authentication.TokenInjectingRoundTripper{
188-
Tripper: rt,
189-
TokenGetter: tokenGetter,
190-
Key: namespacedName,
191-
}
192-
}
193-
return tempConfig, nil
194-
}
169+
clientRestConfigMapper := action.ServiceAccountRestConfigMapper(tokenGetter)
195170

196171
cfgGetter, err := helmclient.NewActionConfigGetter(mgr.GetConfig(), mgr.GetRESTMapper(),
197-
helmclient.StorageNamespaceMapper(installNamespaceMapper),
198-
helmclient.ClientNamespaceMapper(installNamespaceMapper),
199-
helmclient.RestConfigMapper(restConfigMapper),
172+
helmclient.StorageDriverMapper(action.ChunkedStorageDriverMapper(coreClient, mgr.GetAPIReader(), systemNamespace)),
173+
helmclient.ClientNamespaceMapper(func(obj client.Object) (string, error) {
174+
ext := obj.(*ocv1alpha1.ClusterExtension)
175+
return ext.Spec.InstallNamespace, nil
176+
}),
177+
helmclient.ClientRestConfigMapper(clientRestConfigMapper),
200178
)
201179
if err != nil {
202180
setupLog.Error(err, "unable to config for creating helm client")
@@ -283,7 +261,7 @@ func main() {
283261
Applier: applier,
284262
InstalledBundleGetter: &controllers.DefaultInstalledBundleGetter{ActionClientGetter: acg},
285263
Finalizers: clusterExtensionFinalizers,
286-
Watcher: contentmanager.New(restConfigMapper, mgr.GetConfig(), mgr.GetRESTMapper()),
264+
Watcher: contentmanager.New(clientRestConfigMapper, mgr.GetConfig(), mgr.GetRESTMapper()),
287265
}).SetupWithManager(mgr); err != nil {
288266
setupLog.Error(err, "unable to create controller", "controller", "ClusterExtension")
289267
os.Exit(1)

config/base/rbac/role.yaml

+20-12
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,6 @@ rules:
2424
verbs:
2525
- list
2626
- watch
27-
- apiGroups:
28-
- ""
29-
resources:
30-
- secrets
31-
verbs:
32-
- create
33-
- delete
34-
- get
35-
- list
36-
- patch
37-
- update
38-
- watch
3927
- apiGroups:
4028
- ""
4129
resources:
@@ -65,3 +53,23 @@ rules:
6553
verbs:
6654
- patch
6755
- update
56+
---
57+
apiVersion: rbac.authorization.k8s.io/v1
58+
kind: Role
59+
metadata:
60+
name: manager-role
61+
namespace: system
62+
rules:
63+
- apiGroups:
64+
- ""
65+
resources:
66+
- secrets
67+
verbs:
68+
- create
69+
- delete
70+
- deletecollection
71+
- get
72+
- list
73+
- patch
74+
- update
75+
- watch

config/base/rbac/role_binding.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,17 @@ subjects:
1010
- kind: ServiceAccount
1111
name: controller-manager
1212
namespace: system
13+
---
14+
apiVersion: rbac.authorization.k8s.io/v1
15+
kind: RoleBinding
16+
metadata:
17+
name: manager-rolebinding
18+
namespace: system
19+
roleRef:
20+
apiGroup: rbac.authorization.k8s.io
21+
kind: Role
22+
name: manager-role
23+
subjects:
24+
- kind: ServiceAccount
25+
name: controller-manager
26+
namespace: system
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,104 @@
1+
---
2+
apiVersion: v1
3+
kind: Namespace
4+
metadata:
5+
name: argocd
6+
---
7+
apiVersion: v1
8+
kind: ServiceAccount
9+
metadata:
10+
name: argocd-installer
11+
namespace: argocd
12+
---
13+
apiVersion: rbac.authorization.k8s.io/v1
14+
kind: ClusterRoleBinding
15+
metadata:
16+
name: argocd-installer-binding
17+
roleRef:
18+
apiGroup: rbac.authorization.k8s.io
19+
kind: ClusterRole
20+
name: argocd-installer-clusterrole
21+
subjects:
22+
- kind: ServiceAccount
23+
name: argocd-installer
24+
namespace: argocd
25+
---
26+
apiVersion: rbac.authorization.k8s.io/v1
27+
kind: ClusterRole
28+
metadata:
29+
name: argocd-installer-clusterrole
30+
rules:
31+
- apiGroups: ["*"]
32+
resources: ["*"]
33+
verbs: ["*"]
34+
- apiGroups: [apiextensions.k8s.io]
35+
resources: [customresourcedefinitions]
36+
verbs: [get, list, watch, create, update, patch, delete]
37+
resourceNames:
38+
- appprojects.argoproj.io
39+
- argocds.argoproj.io
40+
- applications.argoproj.io
41+
- argocdexports.argoproj.io
42+
- applicationsets.argoproj.io
43+
- apiGroups: [rbac.authorization.k8s.io]
44+
resources: [clusterroles]
45+
verbs: [get, list, watch, create, update, patch, delete]
46+
resourceNames:
47+
- argocd-operator.v0-1dhiybrldl1gyksid1dk2dqjsc72psdybc7iyvse5gpx
48+
- argocd-operator-metrics-reader
49+
- argocd-operator.v0-22gmilmgp91wu25is5i2ec598hni8owq3l71bbkl7iz3
50+
- apiGroups: [rbac.authorization.k8s.io]
51+
resources: [clusterrolebindings]
52+
verbs: [get, list, watch, create, update, patch, delete]
53+
resourceNames:
54+
- argocd-operator.v0-1dhiybrldl1gyksid1dk2dqjsc72psdybc7iyvse5gpx
55+
- argocd-operator.v0-22gmilmgp91wu25is5i2ec598hni8owq3l71bbkl7iz3
56+
---
57+
apiVersion: rbac.authorization.k8s.io/v1
58+
kind: Role
59+
metadata:
60+
name: argocd-installer-role
61+
namespace: argocd
62+
rules:
63+
- apiGroups: [""]
64+
resources: [serviceaccounts]
65+
verbs: [get, list, watch, create, update, patch, delete]
66+
resourceNames: [argocd-operator-controller-manager]
67+
- apiGroups: [""]
68+
resources: [configmaps]
69+
verbs: [get, list, watch, create, update, patch, delete]
70+
resourceNames: [argocd-operator-manager-config]
71+
- apiGroups: [""]
72+
resources: [services]
73+
verbs: [get, list, watch, create, update, patch, delete]
74+
resourceNames: [argocd-operator-controller-manager-metrics-service]
75+
- apiGroups: [apps]
76+
resources: [deployments]
77+
verbs: [get, list, watch, create, update, patch, delete]
78+
resourceNames: [argocd-operator-controller-manager]
79+
---
80+
apiVersion: rbac.authorization.k8s.io/v1
81+
kind: RoleBinding
82+
metadata:
83+
name: argocd-installer-binding
84+
namespace: argocd
85+
roleRef:
86+
apiGroup: rbac.authorization.k8s.io
87+
kind: Role
88+
name: argocd-installer-role
89+
subjects:
90+
- kind: ServiceAccount
91+
name: argocd-installer
92+
namespace: argocd
93+
---
194
apiVersion: olm.operatorframework.io/v1alpha1
295
kind: ClusterExtension
396
metadata:
4-
name: clusterextension-sample
97+
name: argocd
598
spec:
6-
installNamespace: default
99+
installNamespace: argocd
7100
packageName: argocd-operator
8101
version: 0.6.0
9102
serviceAccount:
10-
name: default
103+
name: argocd-installer
104+
---

go.mod

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
github.com/onsi/gomega v1.34.1
1818
github.com/operator-framework/api v0.26.0
1919
github.com/operator-framework/catalogd v0.20.0
20-
github.com/operator-framework/helm-operator-plugins v0.3.1
20+
github.com/operator-framework/helm-operator-plugins v0.4.0
2121
github.com/operator-framework/operator-registry v1.45.0
2222
github.com/spf13/pflag v1.0.5
2323
github.com/stretchr/testify v1.9.0
@@ -100,9 +100,9 @@ require (
100100
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
101101
github.com/dimchansky/utfbom v1.1.1 // indirect
102102
github.com/distribution/reference v0.6.0 // indirect
103-
github.com/docker/cli v27.0.3+incompatible // indirect
103+
github.com/docker/cli v27.1.1+incompatible // indirect
104104
github.com/docker/distribution v2.8.3+incompatible // indirect
105-
github.com/docker/docker v26.1.4+incompatible // indirect
105+
github.com/docker/docker v27.1.1+incompatible // indirect
106106
github.com/docker/docker-credential-helpers v0.8.1 // indirect
107107
github.com/docker/go-connections v0.5.0 // indirect
108108
github.com/docker/go-metrics v0.0.1 // indirect

go.sum

+6-6
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,12 @@ github.com/distribution/distribution/v3 v3.0.0-alpha.1 h1:jn7I1gvjOvmLztH1+1cLiU
208208
github.com/distribution/distribution/v3 v3.0.0-alpha.1/go.mod h1:LCp4JZp1ZalYg0W/TN05jarCQu+h4w7xc7ZfQF4Y/cY=
209209
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
210210
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
211-
github.com/docker/cli v27.0.3+incompatible h1:usGs0/BoBW8MWxGeEtqPMkzOY56jZ6kYlSN5BLDioCQ=
212-
github.com/docker/cli v27.0.3+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
211+
github.com/docker/cli v27.1.1+incompatible h1:goaZxOqs4QKxznZjjBWKONQci/MywhtRv2oNn0GkeZE=
212+
github.com/docker/cli v27.1.1+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
213213
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
214214
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
215-
github.com/docker/docker v26.1.4+incompatible h1:vuTpXDuoga+Z38m1OZHzl7NKisKWaWlhjQk7IDPSLsU=
216-
github.com/docker/docker v26.1.4+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
215+
github.com/docker/docker v27.1.1+incompatible h1:hO/M4MtV36kzKldqnA37IWhebRA+LnqqcqDja6kVaKY=
216+
github.com/docker/docker v27.1.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
217217
github.com/docker/docker-credential-helpers v0.7.0/go.mod h1:rETQfLdHNT3foU5kuNkFR1R1V12OJRRO5lzt2D1b5X0=
218218
github.com/docker/docker-credential-helpers v0.8.1 h1:j/eKUktUltBtMzKqmfLB0PAgqYyMHOp5vfsD1807oKo=
219219
github.com/docker/docker-credential-helpers v0.8.1/go.mod h1:P3ci7E3lwkZg6XiHdRKft1KckHiO9a2rNtyFbZ/ry9M=
@@ -590,8 +590,8 @@ github.com/operator-framework/api v0.26.0 h1:YVntU2NkVl5zSLLwK5kFcH6P3oSvN9QDgTs
590590
github.com/operator-framework/api v0.26.0/go.mod h1:3IxOwzVUeGxYlzfwKCcfCyS+q3EEhWA/4kv7UehbeyM=
591591
github.com/operator-framework/catalogd v0.20.0 h1:m5ugxf9fjEUaNHy81lSu6jFzTEt0XpEo44+T7g9On+U=
592592
github.com/operator-framework/catalogd v0.20.0/go.mod h1:F4KehkAI/bpDI4IVXNxQ7dlWtVBYvc2qkxSa7mIFGRk=
593-
github.com/operator-framework/helm-operator-plugins v0.3.1 h1:D8hF0ufF+2ZtuttYUu4yBlsmHvic/zENm6n9h83ITI0=
594-
github.com/operator-framework/helm-operator-plugins v0.3.1/go.mod h1:5Kx1PyLnRVPyQmLq+frv+HJgSZzXG+W6LavSCxzm8sI=
593+
github.com/operator-framework/helm-operator-plugins v0.4.0 h1:JuN4u7+8XbyK7nnwj5A4eQwpnA9q3DmlZGGFJr7nBDk=
594+
github.com/operator-framework/helm-operator-plugins v0.4.0/go.mod h1:v+6lqkG1vNg64y4WwEpnLn+b/Sr0gLfrWPIjsHci+E8=
595595
github.com/operator-framework/operator-lib v0.14.0 h1:er+BgZymZD1im2wytLJiPLZpGALAX6N0gXaHx3PKbO4=
596596
github.com/operator-framework/operator-lib v0.14.0/go.mod h1:wUu4Xb9xzXnIpglvaZ3yucTMSlqGXHIoUEH9+5gWiu0=
597597
github.com/operator-framework/operator-registry v1.45.0 h1:9c5NshWjPncdZtWEY0cfMnAjx3pShVnjw5UmZXp/xNE=

internal/action/restconfig.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package action
2+
3+
import (
4+
"context"
5+
"net/http"
6+
7+
"k8s.io/apimachinery/pkg/types"
8+
"k8s.io/client-go/rest"
9+
"sigs.k8s.io/controller-runtime/pkg/client"
10+
11+
ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
12+
"github.com/operator-framework/operator-controller/internal/authentication"
13+
)
14+
15+
func ServiceAccountRestConfigMapper(tokenGetter *authentication.TokenGetter) func(ctx context.Context, o client.Object, c *rest.Config) (*rest.Config, error) {
16+
return func(ctx context.Context, o client.Object, c *rest.Config) (*rest.Config, error) {
17+
cExt := o.(*ocv1alpha1.ClusterExtension)
18+
saKey := types.NamespacedName{
19+
Name: cExt.Spec.ServiceAccount.Name,
20+
Namespace: cExt.Spec.InstallNamespace,
21+
}
22+
saConfig := rest.AnonymousClientConfig(c)
23+
saConfig.Wrap(func(rt http.RoundTripper) http.RoundTripper {
24+
return &authentication.TokenInjectingRoundTripper{
25+
Tripper: rt,
26+
TokenGetter: tokenGetter,
27+
Key: saKey,
28+
}
29+
})
30+
return saConfig, nil
31+
}
32+
}

0 commit comments

Comments
 (0)