Skip to content

Commit

Permalink
Incorporate changes from review
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Berger <alex-berger@gmx.ch>
  • Loading branch information
alex-berger committed Feb 2, 2021
1 parent 6a10dcb commit 16c323f
Show file tree
Hide file tree
Showing 7 changed files with 353 additions and 31 deletions.
15 changes: 7 additions & 8 deletions api/v2beta1/helmrelease_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
kustypes "sigs.k8s.io/kustomize/api/types"

"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/pkg/runtime/dependency"
Expand All @@ -33,28 +32,28 @@ import (
const HelmReleaseKind = "HelmRelease"
const HelmReleaseFinalizer = "finalizers.fluxcd.io"

// PatcheJSON6902 JSON 6902 patches
type PatcheJSON6902 struct {
// PatchJSON6902 contains a JSON patch and the target it applies to.
type PatchJSON6902 struct {
// Patch is the YAML content of a patch.
Patch []apiextensionsv1.JSON `json:"patch,omitempty" yaml:"patch,omitempty"`

// Target points to the resources that the patch is applied to
Target kustypes.Selector `json:"target,omitempty" yaml:"target,omitempty"`
// Target points to the resources that the patch is applied to.
Target Selector `json:"target,omitempty" yaml:"target,omitempty"`
}

// Kustomize Helm PostRenderer specification.
type Kustomize struct {
// Strategic merge patches, defined as inline YAML objects.
// +optional
PatchesStrategicMerge []apiextensionsv1.JSON `json:"patchesStrategicMerge,omitempty"`
// Json 6902 patches, defined as inline YAML objects.
// JSON 6902 patches, defined as inline YAML objects.
// +optional
PatchesJSON6902 []PatcheJSON6902 `json:"patchesJson6902,omitempty"`
PatchesJSON6902 []PatchJSON6902 `json:"patchesJson6902,omitempty"`
// Images is a list of (image name, new name, new tag or digest)
// for changing image names, tags or digests. This can also be achieved with a
// patch, but this operator is simpler to specify.
// +optional
Images []kustypes.Image `json:"images,omitempty" yaml:"images,omitempty"`
Images []Image `json:"images,omitempty" yaml:"images,omitempty"`
}

// PostRenderer contains a Helm PostRenderer specification.
Expand Down
45 changes: 45 additions & 0 deletions api/v2beta1/kustomization_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package v2beta1

// Image contains an image name, a new name, a new tag or digest,
// which will replace the original name and tag.
type Image struct {
// Name is a tag-less image name.
Name string `json:"name,omitempty" yaml:"name,omitempty"`

// NewName is the value used to replace the original name.
NewName string `json:"newName,omitempty" yaml:"newName,omitempty"`

// NewTag is the value used to replace the original tag.
NewTag string `json:"newTag,omitempty" yaml:"newTag,omitempty"`

// Digest is the value used to replace the original image tag.
// If digest is present NewTag value is ignored.
Digest string `json:"digest,omitempty" yaml:"digest,omitempty"`
}

// Gvk identifies a Kubernetes API type.
// https://github.com/kubernetes/community/blob/master/contributors/design-proposals/api-machinery/api-group.md
type Gvk struct {
Group string `json:"group,omitempty" yaml:"group,omitempty"`
Version string `json:"version,omitempty" yaml:"version,omitempty"`
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
}

// Selector specifies a set of resources.
// Any resource that matches intersection of all conditions
// is included in this set.
type Selector struct {
Gvk `json:",inline,omitempty" yaml:",inline,omitempty"`
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`

// AnnotationSelector is a string that follows the label selection expression
// https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#api
// It matches with the resource annotations.
AnnotationSelector string `json:"annotationSelector,omitempty" yaml:"annotationSelector,omitempty"`

// LabelSelector is a string that follows the label selection expression
// https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#api
// It matches with the resource labels.
LabelSelector string `json:"labelSelector,omitempty" yaml:"labelSelector,omitempty"`
}
59 changes: 52 additions & 7 deletions api/v2beta1/zz_generated.deepcopy.go

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

7 changes: 4 additions & 3 deletions config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,10 @@ spec:
type: object
type: array
patchesJson6902:
description: Json 6902 patches, defined as inline YAML objects.
description: JSON 6902 patches, defined as inline YAML objects.
items:
description: PatcheJSON6902 JSON 6902 patches
description: PatchJSON6902 contains a JSON patch and the
target it applies to.
properties:
patch:
description: Patch is the YAML content of a patch.
Expand All @@ -264,7 +265,7 @@ spec:
type: array
target:
description: Target points to the resources that the
patch is applied to
patch is applied to.
properties:
annotationSelector:
description: AnnotationSelector is a string that
Expand Down
4 changes: 2 additions & 2 deletions controllers/helmrelease_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
v2 "github.com/fluxcd/helm-controller/api/v2beta1"
)

func TestHelmReleaseTypes_unmarshal_PatcheJSON6902(t *testing.T) {
var p v2.PatcheJSON6902
func TestHelmReleaseTypes_unmarshal_PatchJSON6902(t *testing.T) {
var p v2.PatchJSON6902
err := json.Unmarshal([]byte(`{"target": {"namespace": "ns", "name": "x", "kind": "k", "version": "v"},"patch": [{"op": "add", "path": "/some/new/path", "value": "value"}]}`), &p)
if err != nil {
t.Error(err)
Expand Down
Loading

0 comments on commit 16c323f

Please sign in to comment.