Skip to content

🌱 Helm extension prototype #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ run: docker-build kind-cluster kind-load kind-deploy #HELP Build the operator-co

.PHONY: docker-build
docker-build: build-linux #EXHELP Build docker image for operator-controller with GOOS=linux and local GOARCH.
$(CONTAINER_RUNTIME) build -t $(IMG) -f Dockerfile ./bin/linux
$(CONTAINER_RUNTIME) build --load -t $(IMG) -f Dockerfile ./bin/linux

#SECTION Release
ifeq ($(origin ENABLE_RELEASE_PIPELINE), undefined)
Expand Down
13 changes: 13 additions & 0 deletions api/v1alpha1/clusterextension_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ type ClusterExtensionInstallConfig struct {
// resources that are included in the bundle of content being applied.
ServiceAccount ServiceAccountReference `json:"serviceAccount"`

// configSource is an optional field that can be used to reference a configMap
// containing helm values when installing an extension that is packaged as a helm chart
//
//+optional
ConfigSources *ConfigSourceReferences `json:"configMap,omitempty"`

// preflight is an optional field that can be used to configure the preflight checks run before installation or upgrade of the content for the package specified in the packageName field.
//
// When specified, it overrides the default configuration of the preflight checks that are required to execute successfully during an install/upgrade operation.
Expand Down Expand Up @@ -376,6 +382,13 @@ type ServiceAccountReference struct {
Name string `json:"name"`
}

// ConfigSourceReference can references a configMap, a secret, plain text config
type ConfigSourceReferences struct {
ConfigMapNames []string `json:"configMapNames,omitempty"`
SecretNames []string `json:"secretNames,omitempty"`
TextConfigs []string `json:"textConfigs,omitempty"`
}

// PreflightConfig holds the configuration for the preflight checks. If used, at least one preflight check must be non-nil.
// +kubebuilder:validation:XValidation:rule="has(self.crdUpgradeSafety)",message="at least one of [crdUpgradeSafety] are required when preflight is specified"
type PreflightConfig struct {
Expand Down
35 changes: 35 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 46 additions & 3 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,20 @@ func main() {
os.Exit(1)
}

pureHelmGetter, err := helmclient.NewActionConfigGetter(mgr.GetConfig(), mgr.GetRESTMapper(),
helmclient.StorageDriverMapper(action.PureHelmStorageDriverMapper(clientRestConfigMapper, mgr.GetAPIReader())),
helmclient.ClientNamespaceMapper(func(obj client.Object) (string, error) {
ext := obj.(*ocv1alpha1.ClusterExtension)
return ext.Spec.Install.Namespace, nil
}),
// helmclient.StorageRestConfigMapper(clientRestConfigMapper),
helmclient.ClientRestConfigMapper(clientRestConfigMapper),
)
if err != nil {
setupLog.Error(err, "unable to config for creating helm client")
os.Exit(1)
}

acg, err := action.NewWrappedActionClientGetter(cfgGetter,
helmclient.WithFailureRollbacks(false),
)
Expand All @@ -214,6 +228,14 @@ func main() {
os.Exit(1)
}

phg, err := action.NewWrappedActionClientGetter(pureHelmGetter,
helmclient.WithFailureRollbacks(false),
)
if err != nil {
setupLog.Error(err, "unable to create helm client")
os.Exit(1)
}

certPoolWatcher, err := httputil.NewCertPoolWatcher(caCertDir, ctrl.Log.WithName("cert-pool"))
if err != nil {
setupLog.Error(err, "unable to create CA certificate pool")
Expand Down Expand Up @@ -284,11 +306,33 @@ func main() {
crdupgradesafety.NewPreflight(aeClient.CustomResourceDefinitions()),
}

applier := &applier.Helm{
olmApplier := &applier.Helm{
ActionClientGetter: acg,
Preflights: preflights,
}

helmEngine := &controllers.Engine{
Unpacker: &source.TarGZ{
BaseCachePath: filepath.Join(cachePath, "charts"),
},
Applier: &applier.Helmer{
ActionClientGetter: phg,
TokenGetter: tokenGetter,
},
}

olmEngine := &controllers.Engine{
Unpacker: unpacker,
Applier: olmApplier,
}

enginator := &controllers.Enginator{
Router: map[string]*controllers.Engine{
"helm": helmEngine,
},
DefaultEngine: olmEngine,
}

cm := contentmanager.NewManager(clientRestConfigMapper, mgr.GetConfig(), mgr.GetRESTMapper())
err = clusterExtensionFinalizers.Register(controllers.ClusterExtensionCleanupContentManagerCacheFinalizer, finalizers.FinalizerFunc(func(ctx context.Context, obj client.Object) (crfinalizer.Result, error) {
ext := obj.(*ocv1alpha1.ClusterExtension)
Expand All @@ -303,8 +347,7 @@ func main() {
if err = (&controllers.ClusterExtensionReconciler{
Client: cl,
Resolver: resolver,
Unpacker: unpacker,
Applier: applier,
Enginator: enginator,
InstalledBundleGetter: &controllers.DefaultInstalledBundleGetter{ActionClientGetter: acg},
Finalizers: clusterExtensionFinalizers,
Manager: cm,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ spec:
serviceAccount:
name: example-sa
properties:
configMap:
description: |-
configSource is an optional field that can be used to reference a configMap
containing helm values when installing an extension that is packaged as a helm chart
properties:
configMapNames:
items:
type: string
type: array
secretNames:
items:
type: string
type: array
textConfigs:
items:
type: string
type: array
type: object
namespace:
description: |-
namespace is a reference to the Namespace in which the bundle of
Expand Down
39 changes: 39 additions & 0 deletions config/samples/argocd-helm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: argocd-helm
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: argocd-helm-installer
namespace: argocd-helm
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: argocd-helm-cluster-admin-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: argocd-helm-installer
namespace: argocd-helm
---
apiVersion: olm.operatorframework.io/v1alpha1
kind: ClusterExtension
metadata:
name: argocd-helm
spec:
source:
sourceType: Catalog
catalog:
packageName: argocd-helm
version: 7.6.8
install:
namespace: argocd-helm
serviceAccount:
name: argocd-helm-installer
2 changes: 1 addition & 1 deletion config/samples/catalogd_operatorcatalog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ spec:
source:
type: Image
image:
ref: quay.io/operatorhubio/catalog:latest
ref: docker.io/perdasilva/catalog:2
pollInterval: 10m
42 changes: 42 additions & 0 deletions config/samples/metrics-server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: metrics-server
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: metrics-server-installer
namespace: metrics-server
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: metrics-server-cluster-admin-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: metrics-server-installer
namespace: metrics-server
---
apiVersion: olm.operatorframework.io/v1alpha1
kind: ClusterExtension
metadata:
name: metrics-server
spec:
source:
sourceType: Catalog
catalog:
packageName: metrics-server
version: 3.12.0
install:
namespace: metrics-server
serviceAccount:
name: metrics-server-installer
configSources:
configMaps:
- "values"
Loading