Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/opencontainers/go-digest"
"github.com/werf/3p-fluxcd-pkg/chartutil"
helmchartutil "helm.sh/helm/v3/pkg/chartutil"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -91,7 +92,8 @@ func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reco
return reconcile.Result{}, nil
}

err := r.statusManager.InitializeConditions(ctx, addon,
err := r.statusManager.InitializeConditions(
ctx, addon,
helmv1alpha1.ConditionTypeReady,
helmv1alpha1.ConditionTypeManaged,
helmv1alpha1.ConditionTypeInstalled,
Expand Down Expand Up @@ -132,6 +134,15 @@ func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reco
)})
}

if err := r.reconcileAddonNamespace(ctx, addon); err != nil {
return reconcile.Result{}, r.statusManager.Update(ctx, addon, status.NoopStatusMutator, status.NoopStatusMapper, services.ReleaseResult{Status: status.Failed(
addon,
helmv1alpha1.ReasonFailed,
fmt.Sprintf("Failed to reconcile target namespace: %s", err.Error()),
err,
)})
}

var chartRes services.ChartResult
var repoRes services.OCIRepoResult
var releaseRes services.ReleaseResult
Expand Down Expand Up @@ -245,6 +256,33 @@ func (r *Reconciler) reconcileDelete(ctx context.Context, addon *helmv1alpha1.He
return reconcile.Result{}, nil
}

func (r *Reconciler) reconcileAddonNamespace(ctx context.Context, addon *helmv1alpha1.HelmClusterAddon) error {
ns := &corev1.Namespace{}

err := r.Get(ctx, client.ObjectKey{Name: addon.Spec.Namespace}, ns)
if err != nil {
if !apierrors.IsNotFound(err) {
return fmt.Errorf("getting namespace: %w", err)
}

ns = &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: addon.Spec.Namespace,
},
}

err = r.Create(ctx, ns)
if err != nil {
if apierrors.IsAlreadyExists(err) {
return nil
}
return fmt.Errorf("creating namespace: %w", err)
}
}

return nil
}

func (r *Reconciler) reconcileForceAnnotation(ctx context.Context, req reconcile.Request) error {
var addon helmv1alpha1.HelmClusterAddon

Expand Down
8 changes: 8 additions & 0 deletions templates/operator-helm-controller/rbac-for-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ metadata:
{{- include "helm_lib_module_labels" (list .) | nindent 2 }}
name: d8:{{ .Chart.Name }}:operator-helm-controller
rules:
- apiGroups:
- ""
resources:
- namespaces
verbs:
- create
- get
- list
- apiGroups:
- authentication.k8s.io
resources:
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/internal/framework/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package framework

import "os"

const PostCleanUpEnv = "POST_CLEANUP"
const PostCleanUpEnv = "E2E_POST_CLEANUP"

func IsCleanUpNeeded() bool {
return os.Getenv(PostCleanUpEnv) != "no"
Expand Down
Loading