Skip to content

Commit

Permalink
Merge pull request #4775 from fluxcd/helmrelease-ga
Browse files Browse the repository at this point in the history
Update `HelmRelease` API to v2 (GA)
  • Loading branch information
stefanprodan committed May 9, 2024
2 parents 54f33ec + d5aedac commit 6981683
Show file tree
Hide file tree
Showing 33 changed files with 196 additions and 194 deletions.
19 changes: 9 additions & 10 deletions cmd/flux/create_helmrelease.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Flux authors
Copyright 2024 The Flux authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -24,12 +24,6 @@ import (
"strings"
"time"

"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/pkg/runtime/transform"

"github.com/fluxcd/flux2/v2/internal/flags"
"github.com/fluxcd/flux2/v2/internal/utils"

"github.com/spf13/cobra"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -39,14 +33,19 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/yaml"

helmv2 "github.com/fluxcd/helm-controller/api/v2beta2"
helmv2 "github.com/fluxcd/helm-controller/api/v2"
"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/pkg/runtime/transform"

"github.com/fluxcd/flux2/v2/internal/flags"
"github.com/fluxcd/flux2/v2/internal/utils"
)

var createHelmReleaseCmd = &cobra.Command{
Use: "helmrelease [name]",
Aliases: []string{"hr"},
Short: "Create or update a HelmRelease resource",
Long: withPreviewNote(`The helmrelease create command generates a HelmRelease resource for a given HelmRepository source.`),
Long: `The helmrelease create command generates a HelmRelease resource for a given HelmRepository source.`,
Example: ` # Create a HelmRelease with a chart from a HelmRepository source
flux create hr podinfo \
--interval=10m \
Expand Down Expand Up @@ -309,7 +308,7 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
}
logger.Successf("HelmRelease %s is ready", name)

logger.Successf("applied revision %s", helmRelease.Status.LastAppliedRevision)
logger.Successf("applied revision %s", getHelmReleaseRevision(helmRelease))
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/create_kustomization.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/controller-runtime/pkg/client"

helmv2 "github.com/fluxcd/helm-controller/api/v2beta2"
helmv2 "github.com/fluxcd/helm-controller/api/v2"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1"
"github.com/fluxcd/pkg/apis/meta"

Expand Down
6 changes: 3 additions & 3 deletions cmd/flux/delete_helmrelease.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Flux authors
Copyright 2024 The Flux authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -19,14 +19,14 @@ package main
import (
"github.com/spf13/cobra"

helmv2 "github.com/fluxcd/helm-controller/api/v2beta2"
helmv2 "github.com/fluxcd/helm-controller/api/v2"
)

var deleteHelmReleaseCmd = &cobra.Command{
Use: "helmrelease [name]",
Aliases: []string{"hr"},
Short: "Delete a HelmRelease resource",
Long: withPreviewNote("The delete helmrelease command removes the given HelmRelease from the cluster."),
Long: "The delete helmrelease command removes the given HelmRelease from the cluster.",
Example: ` # Delete a Helm release and the Kubernetes resources created by it
flux delete hr podinfo`,
ValidArgsFunction: resourceNamesCompletionFunc(helmv2.GroupVersion.WithKind(helmv2.HelmReleaseKind)),
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"sigs.k8s.io/controller-runtime/pkg/client"

helmv2 "github.com/fluxcd/helm-controller/api/v2beta2"
helmv2 "github.com/fluxcd/helm-controller/api/v2"
autov1 "github.com/fluxcd/image-automation-controller/api/v1beta2"
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1"
Expand Down
6 changes: 3 additions & 3 deletions cmd/flux/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ spec:
timeout: 1m0s
url: ssh://git@github.com/example/repo
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: podinfo
Expand All @@ -95,7 +95,7 @@ spec:
version: '*'
interval: 5m0s
---
apiVersion: source.toolkit.fluxcd.io/v1beta2
apiVersion: source.toolkit.fluxcd.io/v1
kind: HelmRepository
metadata:
name: podinfo
Expand All @@ -104,7 +104,7 @@ spec:
interval: 1m0s
url: https://stefanprodan.github.io/podinfo
---
apiVersion: source.toolkit.fluxcd.io/v1beta2
apiVersion: source.toolkit.fluxcd.io/v1
kind: HelmChart
metadata:
name: default-podinfo
Expand Down
6 changes: 3 additions & 3 deletions cmd/flux/export_helmrelease.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Flux authors
Copyright 2024 The Flux authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -20,14 +20,14 @@ import (
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

helmv2 "github.com/fluxcd/helm-controller/api/v2beta2"
helmv2 "github.com/fluxcd/helm-controller/api/v2"
)

var exportHelmReleaseCmd = &cobra.Command{
Use: "helmrelease [name]",
Aliases: []string{"hr"},
Short: "Export HelmRelease resources in YAML format",
Long: withPreviewNote("The export helmrelease command exports one or all HelmRelease resources in YAML format."),
Long: "The export helmrelease command exports one or all HelmRelease resources in YAML format.",
Example: ` # Export all HelmRelease resources
flux export helmrelease --all > kustomizations.yaml
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/get_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/spf13/cobra"
apimeta "k8s.io/apimachinery/pkg/api/meta"

helmv2 "github.com/fluxcd/helm-controller/api/v2beta2"
helmv2 "github.com/fluxcd/helm-controller/api/v2"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1"
notificationv1 "github.com/fluxcd/notification-controller/api/v1"
notificationv1b3 "github.com/fluxcd/notification-controller/api/v1beta3"
Expand Down
15 changes: 11 additions & 4 deletions cmd/flux/get_helmrelease.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Flux authors
Copyright 2024 The Flux authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -25,14 +25,14 @@ import (
"golang.org/x/text/language"
"k8s.io/apimachinery/pkg/runtime"

helmv2 "github.com/fluxcd/helm-controller/api/v2beta2"
helmv2 "github.com/fluxcd/helm-controller/api/v2"
)

var getHelmReleaseCmd = &cobra.Command{
Use: "helmreleases",
Aliases: []string{"hr", "helmrelease"},
Short: "Get HelmRelease statuses",
Long: withPreviewNote("The get helmreleases command prints the statuses of the resources."),
Long: "The get helmreleases command prints the statuses of the resources.",
Example: ` # List all Helm releases and their status
flux get helmreleases`,
ValidArgsFunction: resourceNamesCompletionFunc(helmv2.GroupVersion.WithKind(helmv2.HelmReleaseKind)),
Expand Down Expand Up @@ -72,9 +72,16 @@ func init() {
getCmd.AddCommand(getHelmReleaseCmd)
}

func getHelmReleaseRevision(helmRelease helmv2.HelmRelease) string {
if helmRelease.Status.History != nil && len(helmRelease.Status.History) > 0 {
return helmRelease.Status.History[0].ChartVersion
}
return helmRelease.Status.LastAttemptedRevision
}

func (a helmReleaseListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
item := a.Items[i]
revision := item.Status.LastAppliedRevision
revision := getHelmReleaseRevision(item)
status, msg := statusAndMessage(item.Status.Conditions)
return append(nameColumns(&item, includeNamespace, includeKind),
revision, cases.Title(language.English).String(strconv.FormatBool(item.Spec.Suspend)), status, msg)
Expand Down
4 changes: 2 additions & 2 deletions cmd/flux/helmrelease.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 The Flux authors
Copyright 2024 The Flux authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,7 @@ package main
import (
"sigs.k8s.io/controller-runtime/pkg/client"

helmv2 "github.com/fluxcd/helm-controller/api/v2beta2"
helmv2 "github.com/fluxcd/helm-controller/api/v2"
)

// helmv2.HelmRelease
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/client"

helmv2 "github.com/fluxcd/helm-controller/api/v2beta2"
helmv2 "github.com/fluxcd/helm-controller/api/v2"
"github.com/fluxcd/pkg/apis/meta"

"github.com/fluxcd/flux2/v2/internal/utils"
Expand Down
4 changes: 2 additions & 2 deletions cmd/flux/reconcile_helmrelease.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Flux authors
Copyright 2024 The Flux authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -22,7 +22,7 @@ import (
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/types"

helmv2 "github.com/fluxcd/helm-controller/api/v2beta2"
helmv2 "github.com/fluxcd/helm-controller/api/v2"
sourcev1 "github.com/fluxcd/source-controller/api/v1"
)

Expand Down
6 changes: 3 additions & 3 deletions cmd/flux/resume_helmrelease.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Flux authors
Copyright 2024 The Flux authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,7 @@ import (

"github.com/spf13/cobra"

helmv2 "github.com/fluxcd/helm-controller/api/v2beta2"
helmv2 "github.com/fluxcd/helm-controller/api/v2"
)

var resumeHrCmd = &cobra.Command{
Expand Down Expand Up @@ -55,7 +55,7 @@ func (obj helmReleaseAdapter) setUnsuspended() {
}

func (obj helmReleaseAdapter) successMessage() string {
return fmt.Sprintf("applied revision %s", obj.Status.LastAppliedRevision)
return fmt.Sprintf("applied revision %s", getHelmReleaseRevision(*obj.HelmRelease))
}

func (a helmReleaseListAdapter) resumeItem(i int) resumable {
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/fluxcd/cli-utils/pkg/kstatus/status"
helmv2 "github.com/fluxcd/helm-controller/api/v2beta2"
helmv2 "github.com/fluxcd/helm-controller/api/v2"
autov1 "github.com/fluxcd/image-automation-controller/api/v1beta2"
imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta2"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1"
Expand Down
4 changes: 2 additions & 2 deletions cmd/flux/suspend_helmrelease.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Flux authors
Copyright 2024 The Flux authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,7 @@ package main
import (
"github.com/spf13/cobra"

helmv2 "github.com/fluxcd/helm-controller/api/v2beta2"
helmv2 "github.com/fluxcd/helm-controller/api/v2"
)

var suspendHrCmd = &cobra.Command{
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/testdata/export/helm-release.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: flux-system
Expand Down
4 changes: 2 additions & 2 deletions cmd/flux/testdata/export/objects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ spec:
name: flux-system
namespace: flux-system
---
apiVersion: source.toolkit.fluxcd.io/v1beta2
apiVersion: source.toolkit.fluxcd.io/v1
kind: HelmRepository
metadata:
name: flux-system
Expand All @@ -138,7 +138,7 @@ spec:
name: podinfo
version: '*'
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
name: flux-system
Expand Down
9 changes: 3 additions & 6 deletions cmd/flux/testdata/trace/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ spec:
command: [ "echo hello world" ]
image: busybox
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
labels:
Expand All @@ -59,11 +59,9 @@ status:
status: "True"
type: Ready
helmChart: {{ .fluxns }}/podinfo-podinfo
lastAppliedRevision: 6.3.5
lastAttemptedRevision: 6.3.5
lastAttemptedValuesChecksum: c31db75d05b7515eba2eef47bd71038c74b2e531
---
apiVersion: source.toolkit.fluxcd.io/v1beta2
apiVersion: source.toolkit.fluxcd.io/v1
kind: HelmChart
metadata:
name: podinfo-podinfo
Expand All @@ -90,7 +88,7 @@ status:
type: Ready

---
apiVersion: source.toolkit.fluxcd.io/v1beta2
apiVersion: source.toolkit.fluxcd.io/v1
kind: HelmRepository
metadata:
labels:
Expand Down Expand Up @@ -126,7 +124,6 @@ spec:
sourceRef:
kind: GitRepository
name: flux-system
validation: client
interval: 5m
prune: true
status:
Expand Down
3 changes: 1 addition & 2 deletions cmd/flux/testdata/trace/helmrelease-oci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ kind: Namespace
metadata:
name: {{ .ns }}
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
labels:
Expand Down Expand Up @@ -48,7 +48,6 @@ spec:
sourceRef:
kind: OCIRepository
name: flux-system
validation: client
interval: 5m
prune: false
status:
Expand Down
3 changes: 1 addition & 2 deletions cmd/flux/testdata/trace/helmrelease.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ kind: Namespace
metadata:
name: {{ .ns }}
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
labels:
Expand Down Expand Up @@ -48,7 +48,6 @@ spec:
sourceRef:
kind: GitRepository
name: flux-system
validation: client
interval: 5m
prune: false
status:
Expand Down
Loading

0 comments on commit 6981683

Please sign in to comment.