Skip to content

Commit

Permalink
Depend on the Kustomize API from fluxcd/pkg
Browse files Browse the repository at this point in the history
Signed-off-by: Hidde Beydals <hello@hidde.co>
  • Loading branch information
hiddeco committed Feb 3, 2021
1 parent d753d56 commit 30227ce
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 432 deletions.
1 change: 1 addition & 0 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/fluxcd/helm-controller/api
go 1.15

require (
github.com/fluxcd/pkg/apis/kustomize v0.0.0-20210203170140-c9274a8cd235
github.com/fluxcd/pkg/apis/meta v0.7.0
github.com/fluxcd/pkg/runtime v0.6.2
k8s.io/apiextensions-apiserver v0.20.2
Expand Down
4 changes: 4 additions & 0 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fluxcd/pkg/apis/kustomize v0.0.0-20210203162456-8b60f01eda32 h1:1aMt0EQ7Wd6sJhH/VjNo2l9JvC24zNFi00XF7Hw/A6Q=
github.com/fluxcd/pkg/apis/kustomize v0.0.0-20210203162456-8b60f01eda32/go.mod h1:JAFPfnRmcrAoG1gNiA8kmEXsnOBuDyZ/F5X4DAQcVV0=
github.com/fluxcd/pkg/apis/kustomize v0.0.0-20210203170140-c9274a8cd235 h1:IBxiuFeaECdJKqBTEHPkQs4wybA9b3rSbRe7w2FAOvk=
github.com/fluxcd/pkg/apis/kustomize v0.0.0-20210203170140-c9274a8cd235/go.mod h1:JAFPfnRmcrAoG1gNiA8kmEXsnOBuDyZ/F5X4DAQcVV0=
github.com/fluxcd/pkg/apis/meta v0.5.0/go.mod h1:aEUuZIawboAAFLlYz/juVJ7KNmlWbBtJFYkOWWmGUR4=
github.com/fluxcd/pkg/apis/meta v0.7.0 h1:5e8gm4OLqjuKWdrOIY5DEEsjcwzyJFK8rCDesJ+V8IY=
github.com/fluxcd/pkg/apis/meta v0.7.0/go.mod h1:yHuY8kyGHYz22I0jQzqMMGCcHViuzC/WPdo9Gisk8Po=
Expand Down
14 changes: 3 additions & 11 deletions api/v2beta1/helmrelease_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,14 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

"github.com/fluxcd/pkg/apis/kustomize"
"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/pkg/runtime/dependency"
)

const HelmReleaseKind = "HelmRelease"
const HelmReleaseFinalizer = "finalizers.fluxcd.io"

// 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 Selector `json:"target,omitempty" yaml:"target,omitempty"`
}

// Kustomize Helm PostRenderer specification.
type Kustomize struct {
// Strategic merge patches, defined as inline YAML objects.
Expand All @@ -49,13 +41,13 @@ type Kustomize struct {

// JSON 6902 patches, defined as inline YAML objects.
// +optional
PatchesJSON6902 []PatchJSON6902 `json:"patchesJson6902,omitempty"`
PatchesJSON6902 []kustomize.JSON6902Patch `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 []Image `json:"images,omitempty" yaml:"images,omitempty"`
Images []kustomize.Image `json:"images,omitempty" yaml:"images,omitempty"`
}

// PostRenderer contains a Helm PostRenderer specification.
Expand Down
65 changes: 0 additions & 65 deletions api/v2beta1/kustomization_types.go

This file was deleted.

76 changes: 4 additions & 72 deletions api/v2beta1/zz_generated.deepcopy.go

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

51 changes: 46 additions & 5 deletions config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -250,44 +250,85 @@ spec:
description: NewTag is the value used to replace the
original tag.
type: string
required:
- name
type: object
type: array
patchesJson6902:
description: JSON 6902 patches, defined as inline YAML objects.
items:
description: PatchJSON6902 contains a JSON patch and the
target it applies to.
description: JSON6902Patch contains a JSON6902 patch and
the target the patch should be applied to.
properties:
patch:
description: Patch is the YAML content of a patch.
description: Patch contains the JSON6902 patch document
with an array of operation objects.
items:
x-kubernetes-preserve-unknown-fields: true
description: JSON6902 is a JSON6902 operation object.
https://tools.ietf.org/html/rfc6902#section-4
properties:
from:
type: string
op:
enum:
- test
- remove
- add
- replace
- move
- copy
type: string
path:
type: string
value:
x-kubernetes-preserve-unknown-fields: true
required:
- op
- path
type: object
type: array
target:
description: Target points to the resources that the
patch is applied to.
patch document should be applied to.
properties:
annotationSelector:
description: 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.
type: string
group:
description: Group is the API group to select
resources from. Together with Version and Kind
it is capable of unambiguously identifying and/or
selecting resources. https://github.com/kubernetes/community/blob/master/contributors/design-proposals/api-machinery/api-group.md
type: string
kind:
description: Kind of the API Group to select resources
from. Together with Group and Version it is
capable of unambiguously identifying and/or
selecting resources. https://github.com/kubernetes/community/blob/master/contributors/design-proposals/api-machinery/api-group.md
type: string
labelSelector:
description: 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.
type: string
name:
description: Name to match resources with.
type: string
namespace:
description: Namespace to select resources from.
type: string
version:
description: Version of the API Group to select
resources from. Together with Group and Kind
it is capable of unambiguously identifying and/or
selecting resources. https://github.com/kubernetes/community/blob/master/contributors/design-proposals/api-machinery/api-group.md
type: string
type: object
required:
- patch
- target
type: object
type: array
patchesStrategicMerge:
Expand Down
20 changes: 19 additions & 1 deletion controllers/helmrelease_types_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
/*
Copyright 2021 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package controllers

import (
"encoding/json"
"testing"

"github.com/fluxcd/pkg/apis/kustomize"

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

func TestHelmReleaseTypes_unmarshal_PatchJSON6902(t *testing.T) {
var p v2.PatchJSON6902
var p kustomize.JSON6902Patch
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 30227ce

Please sign in to comment.