Skip to content
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

Update HelmRelease API to v2 (GA) #4775

Merged
merged 6 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
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.`,
darkowlzz marked this conversation as resolved.
Show resolved Hide resolved
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
2 changes: 1 addition & 1 deletion 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://[email protected]/example/repo
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
apiVersion: helm.toolkit.fluxcd.io/v2
stefanprodan marked this conversation as resolved.
Show resolved Hide resolved
kind: HelmRelease
metadata:
name: 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
2 changes: 1 addition & 1 deletion cmd/flux/testdata/export/objects.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ spec:
name: podinfo
version: '*'
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
apiVersion: helm.toolkit.fluxcd.io/v2
stefanprodan marked this conversation as resolved.
Show resolved Hide resolved
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
2 changes: 1 addition & 1 deletion 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
stefanprodan marked this conversation as resolved.
Show resolved Hide resolved
kind: HelmRelease
metadata:
labels:
Expand Down
2 changes: 1 addition & 1 deletion 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
stefanprodan marked this conversation as resolved.
Show resolved Hide resolved
kind: HelmRelease
metadata:
labels:
Expand Down
6 changes: 3 additions & 3 deletions cmd/flux/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"k8s.io/cli-runtime/pkg/resource"
"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"
fluxmeta "github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/pkg/oci"
Expand Down Expand Up @@ -64,7 +64,7 @@ You can also trace multiple objects with different resource kinds using <resourc

# API Version and Kind can also be specified explicitly
# Note that either both, kind and api-version, or neither have to be specified.
flux trace redis --kind=helmrelease --api-version=helm.toolkit.fluxcd.io/v2beta2 -n redis`,
flux trace redis --kind=helmrelease --api-version=helm.toolkit.fluxcd.io/v2 -n redis`,
RunE: traceCmdRun,
}

Expand Down Expand Up @@ -448,7 +448,7 @@ Namespace: {{.HelmRelease.Namespace}}
{{- if .HelmRelease.Spec.TargetNamespace }}
Target: {{.HelmRelease.Spec.TargetNamespace}}
{{- end }}
Revision: {{.HelmRelease.Status.LastAppliedRevision}}
Revision: {{.HelmRelease.Status.LastAttemptedRevision}}
{{- if .HelmReleaseReady }}
Status: Last reconciled at {{.HelmReleaseReady.LastTransitionTime}}
Message: {{.HelmReleaseReady.Message}}
Expand Down
4 changes: 2 additions & 2 deletions cmd/flux/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestTrace(t *testing.T) {
},
{
"HelmRelease",
"trace podinfo --kind HelmRelease --api-version=helm.toolkit.fluxcd.io/v2beta2",
"trace podinfo --kind HelmRelease --api-version=helm.toolkit.fluxcd.io/v2",
"testdata/trace/helmrelease.yaml",
"testdata/trace/helmrelease.golden",
map[string]string{
Expand All @@ -59,7 +59,7 @@ func TestTrace(t *testing.T) {
},
{
"HelmRelease from OCI registry",
"trace podinfo --kind HelmRelease --api-version=helm.toolkit.fluxcd.io/v2beta2",
"trace podinfo --kind HelmRelease --api-version=helm.toolkit.fluxcd.io/v2",
"testdata/trace/helmrelease-oci.yaml",
"testdata/trace/helmrelease-oci.golden",
map[string]string{
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/tree_kustomization.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"sigs.k8s.io/yaml"

"github.com/fluxcd/cli-utils/pkg/object"
helmv2 "github.com/fluxcd/helm-controller/api/v2beta2"
helmv2 "github.com/fluxcd/helm-controller/api/v2"
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1"
ssautil "github.com/fluxcd/pkg/ssa/utils"

Expand Down
Loading
Loading