Skip to content

Commit

Permalink
Update flux pkg components
Browse files Browse the repository at this point in the history
Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
  • Loading branch information
relu committed Dec 20, 2021
1 parent 62aea40 commit 0c6552c
Show file tree
Hide file tree
Showing 12 changed files with 796 additions and 348 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
ARG XX_VERSION=1.0.0-rc.2
ARG GO_VERSION=1.17
ARG XX_VERSION=1.1.0

FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx

# Docker buildkit multi-arch build requires golang alpine
FROM --platform=$BUILDPLATFORM golang:1.17-alpine as builder
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine as builder

# Copy the build utilities.
COPY --from=xx / /
Expand Down Expand Up @@ -31,7 +32,7 @@ COPY internal/ internal/
ENV CGO_ENABLED=0
RUN xx-go build -a -o helm-controller main.go

FROM alpine:3.14
FROM alpine:3.15

# link repo to the GitHub Container Registry image
LABEL org.opencontainers.image.source="https://github.com/fluxcd/helm-controller"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ docker-push:
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
.PHONY: controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.5.0)
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.7.0)

# Find or download gen-crd-api-reference-docs
gen-crd-api-reference-docs:
Expand Down
33 changes: 17 additions & 16 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,28 @@ module github.com/fluxcd/helm-controller/api
go 1.17

require (
github.com/fluxcd/pkg/apis/kustomize v0.3.0
github.com/fluxcd/pkg/apis/meta v0.10.1
github.com/fluxcd/pkg/runtime v0.12.2
k8s.io/apiextensions-apiserver v0.22.2
k8s.io/apimachinery v0.22.2
sigs.k8s.io/controller-runtime v0.10.2
github.com/fluxcd/pkg/apis/kustomize v0.3.1
github.com/fluxcd/pkg/apis/meta v0.10.2
github.com/fluxcd/pkg/runtime v0.12.3
k8s.io/apiextensions-apiserver v0.23.1
k8s.io/apimachinery v0.23.1
sigs.k8s.io/controller-runtime v0.11.0
)

require (
github.com/go-logr/logr v0.4.0 // indirect
github.com/go-logr/logr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023 // indirect
golang.org/x/text v0.3.6 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
golang.org/x/net v0.0.0-20211215060638-4ddde0e984e9 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/klog/v2 v2.9.0 // indirect
k8s.io/utils v0.0.0-20210722164352-7f3ee0f31471 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/utils v0.0.0-20211208161948-7d6a63dca704 // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.0 // indirect
)
313 changes: 244 additions & 69 deletions api/go.sum

Large diffs are not rendered by default.

441 changes: 331 additions & 110 deletions config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml

Large diffs are not rendered by default.

29 changes: 14 additions & 15 deletions controllers/helmrelease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"strings"
"time"

"github.com/go-logr/logr"
"github.com/hashicorp/go-retryablehttp"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chartutil"
Expand Down Expand Up @@ -130,7 +129,7 @@ func (c ConditionError) Error() string {

func (r *HelmReleaseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
start := time.Now()
log := logr.FromContext(ctx)
log := ctrl.LoggerFrom(ctx)

var hr v2.HelmRelease
if err := r.Get(ctx, req.NamespacedName, &hr); err != nil {
Expand Down Expand Up @@ -183,7 +182,7 @@ func (r *HelmReleaseReconciler) Reconcile(ctx context.Context, req ctrl.Request)

func (r *HelmReleaseReconciler) reconcile(ctx context.Context, hr v2.HelmRelease) (v2.HelmRelease, ctrl.Result, error) {
reconcileStart := time.Now()
log := logr.FromContext(ctx)
log := ctrl.LoggerFrom(ctx)
// Record the value of the reconciliation request, if any
if v, ok := meta.ReconcileAnnotationValue(hr.GetAnnotations()); ok {
hr.Status.SetLastHandledReconcileRequest(v)
Expand Down Expand Up @@ -275,7 +274,7 @@ type HelmReleaseReconcilerOptions struct {

func (r *HelmReleaseReconciler) reconcileRelease(ctx context.Context,
hr v2.HelmRelease, chart *chart.Chart, values chartutil.Values) (v2.HelmRelease, error) {
log := logr.FromContext(ctx)
log := ctrl.LoggerFrom(ctx)

// Initialize Helm action runner
getter, err := r.getRESTClientGetter(ctx, hr)
Expand Down Expand Up @@ -550,7 +549,7 @@ func (r *HelmReleaseReconciler) composeValues(ctx context.Context, hr v2.HelmRel
if err := r.Get(ctx, namespacedName, resource); err != nil {
if apierrors.IsNotFound(err) {
if v.Optional {
(logr.FromContext(ctx)).
(ctrl.LoggerFrom(ctx)).
Info(fmt.Sprintf("could not find optional %s '%s'", v.Kind, namespacedName))
continue
}
Expand All @@ -562,7 +561,7 @@ func (r *HelmReleaseReconciler) composeValues(ctx context.Context, hr v2.HelmRel
}
if resource == nil {
if v.Optional {
(logr.FromContext(ctx)).Info(fmt.Sprintf("could not find optional %s '%s'", v.Kind, namespacedName))
(ctrl.LoggerFrom(ctx)).Info(fmt.Sprintf("could not find optional %s '%s'", v.Kind, namespacedName))
continue
}
return nil, fmt.Errorf("could not find %s '%s'", v.Kind, namespacedName)
Expand All @@ -583,7 +582,7 @@ func (r *HelmReleaseReconciler) composeValues(ctx context.Context, hr v2.HelmRel
if err := r.Get(ctx, namespacedName, resource); err != nil {
if apierrors.IsNotFound(err) {
if v.Optional {
(logr.FromContext(ctx)).
(ctrl.LoggerFrom(ctx)).
Info(fmt.Sprintf("could not find optional %s '%s'", v.Kind, namespacedName))
continue
}
Expand All @@ -595,7 +594,7 @@ func (r *HelmReleaseReconciler) composeValues(ctx context.Context, hr v2.HelmRel
}
if resource == nil {
if v.Optional {
(logr.FromContext(ctx)).Info(fmt.Sprintf("could not find optional %s '%s'", v.Kind, namespacedName))
(ctrl.LoggerFrom(ctx)).Info(fmt.Sprintf("could not find optional %s '%s'", v.Kind, namespacedName))
continue
}
return nil, fmt.Errorf("could not find %s '%s'", v.Kind, namespacedName)
Expand Down Expand Up @@ -655,17 +654,17 @@ func (r *HelmReleaseReconciler) reconcileDelete(ctx context.Context, hr v2.HelmR
if err != nil {
return ctrl.Result{}, err
}
run, err := runner.NewRunner(getter, hr.GetStorageNamespace(), logr.FromContext(ctx))
run, err := runner.NewRunner(getter, hr.GetStorageNamespace(), ctrl.LoggerFrom(ctx))
if err != nil {
return ctrl.Result{}, err
}
if err := run.Uninstall(hr); err != nil && !errors.Is(err, driver.ErrReleaseNotFound) {
return ctrl.Result{}, err
}
logr.FromContext(ctx).Info("uninstalled Helm release for deleted resource")
ctrl.LoggerFrom(ctx).Info("uninstalled Helm release for deleted resource")

} else {
logr.FromContext(ctx).Info("skipping Helm uninstall for suspended resource")
ctrl.LoggerFrom(ctx).Info("skipping Helm uninstall for suspended resource")
}

// Remove our finalizer from the list and update it.
Expand Down Expand Up @@ -740,7 +739,7 @@ func (r *HelmReleaseReconciler) event(ctx context.Context, hr v2.HelmRelease, re
r.EventRecorder.Event(&hr, "Normal", severity, msg)
objRef, err := reference.GetReference(r.Scheme, &hr)
if err != nil {
logr.FromContext(ctx).Error(err, "unable to send event")
ctrl.LoggerFrom(ctx).Error(err, "unable to send event")
return
}

Expand All @@ -750,7 +749,7 @@ func (r *HelmReleaseReconciler) event(ctx context.Context, hr v2.HelmRelease, re
meta = map[string]string{"revision": revision}
}
if err := r.ExternalEventRecorder.Eventf(*objRef, meta, severity, severity, msg); err != nil {
logr.FromContext(ctx).Error(err, "unable to send event")
ctrl.LoggerFrom(ctx).Error(err, "unable to send event")
return
}
}
Expand All @@ -760,7 +759,7 @@ func (r *HelmReleaseReconciler) recordSuspension(ctx context.Context, hr v2.Helm
if r.MetricsRecorder == nil {
return
}
log := logr.FromContext(ctx)
log := ctrl.LoggerFrom(ctx)

objRef, err := reference.GetReference(r.Scheme, &hr)
if err != nil {
Expand All @@ -782,7 +781,7 @@ func (r *HelmReleaseReconciler) recordReadiness(ctx context.Context, hr v2.HelmR

objRef, err := reference.GetReference(r.Scheme, &hr)
if err != nil {
logr.FromContext(ctx).Error(err, "unable to record readiness metric")
ctrl.LoggerFrom(ctx).Error(err, "unable to record readiness metric")
return
}
if rc := apimeta.FindStatusCondition(hr.Status.Conditions, meta.ReadyCondition); rc != nil {
Expand Down
4 changes: 2 additions & 2 deletions controllers/helmrelease_controller_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import (
"reflect"
"strings"

"github.com/go-logr/logr"
"github.com/hashicorp/go-retryablehttp"
"helm.sh/helm/v3/pkg/chart"
"helm.sh/helm/v3/pkg/chart/loader"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"

sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"

Expand Down Expand Up @@ -69,7 +69,7 @@ func (r *HelmReleaseReconciler) reconcileChart(ctx context.Context, hr *v2.HelmR
hr.Status.HelmChart = chartName.String()
return hc, nil
case helmChartRequiresUpdate(hr, &helmChart):
logr.FromContext(ctx).Info("chart diverged from template", strings.ToLower(sourcev1.HelmChartKind), chartName.String())
ctrl.LoggerFrom(ctx).Info("chart diverged from template", strings.ToLower(sourcev1.HelmChartKind), chartName.String())
helmChart.Spec = hc.Spec
if err = r.Client.Update(ctx, &helmChart); err != nil {
return nil, err
Expand Down
3 changes: 1 addition & 2 deletions controllers/helmrelease_controller_chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/log"

v2 "github.com/fluxcd/helm-controller/api/v2beta1"
)
Expand Down Expand Up @@ -160,7 +159,7 @@ func TestHelmReleaseReconciler_reconcileChart(t *testing.T) {
Client: c,
}

hc, err := r.reconcileChart(logr.NewContext(context.TODO(), log.NullLogger{}), tt.hr)
hc, err := r.reconcileChart(logr.NewContext(context.TODO(), logr.Discard()), tt.hr)
if tt.expectErr {
g.Expect(err).To(HaveOccurred())
g.Expect(hc).To(BeNil())
Expand Down
3 changes: 1 addition & 2 deletions controllers/helmrelease_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/yaml"

v2 "github.com/fluxcd/helm-controller/api/v2beta1"
Expand Down Expand Up @@ -267,7 +266,7 @@ invalid`,
Values: values,
},
}
got, err := r.composeValues(logr.NewContext(context.TODO(), log.NullLogger{}), hr)
got, err := r.composeValues(logr.NewContext(context.TODO(), logr.Discard()), hr)
if (err != nil) != tt.wantErr {
t.Errorf("composeValues() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down
Loading

0 comments on commit 0c6552c

Please sign in to comment.