From 622a87a6631feb95034584eec1e64c22c83fc2d9 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Wed, 3 Feb 2021 18:10:47 +0100 Subject: [PATCH] Depend on the Kustomize API from `fluxcd/pkg` Signed-off-by: Hidde Beydals --- api/go.mod | 1 + api/go.sum | 9 +- api/v2beta1/helmrelease_types.go | 14 +- api/v2beta1/kustomization_types.go | 65 ----- api/v2beta1/zz_generated.deepcopy.go | 76 +----- .../helm.toolkit.fluxcd.io_helmreleases.yaml | 51 +++- controllers/helmrelease_types_test.go | 20 +- docs/api/helmrelease.md | 258 +----------------- docs/spec/v2beta1/helmreleases.md | 58 ++-- go.mod | 1 + go.sum | 5 +- hack/api-docs/config.json | 5 + hack/boilerplate.go.txt | 2 +- internal/runner/post_renderer.go | 16 ++ internal/runner/post_renderer_kustomize.go | 31 ++- internal/runner/runner.go | 2 +- 16 files changed, 154 insertions(+), 460 deletions(-) delete mode 100644 api/v2beta1/kustomization_types.go diff --git a/api/go.mod b/api/go.mod index 178243386..71582f04b 100644 --- a/api/go.mod +++ b/api/go.mod @@ -3,6 +3,7 @@ module github.com/fluxcd/helm-controller/api go 1.15 require ( + github.com/fluxcd/pkg/apis/kustomize v0.0.1 github.com/fluxcd/pkg/apis/meta v0.7.0 github.com/fluxcd/pkg/runtime v0.6.2 k8s.io/apiextensions-apiserver v0.20.2 diff --git a/api/go.sum b/api/go.sum index 320941b71..08dff4fa6 100644 --- a/api/go.sum +++ b/api/go.sum @@ -50,10 +50,8 @@ github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb0 github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= -github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= -github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -113,6 +111,8 @@ 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.1 h1:TkA80R0GopRY27VJqzKyS6ifiKIAfwBd7OHXtV3t2CI= +github.com/fluxcd/pkg/apis/kustomize v0.0.1/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= @@ -150,13 +150,11 @@ github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+ github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M= github.com/go-openapi/jsonpointer v0.18.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M= github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg= -github.com/go-openapi/jsonpointer v0.19.3 h1:gihV7YNZK1iK6Tgwwsxo2rJbD1GTbdm72325Bq8FI3w= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg= github.com/go-openapi/jsonreference v0.17.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I= github.com/go-openapi/jsonreference v0.18.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I= github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc= -github.com/go-openapi/jsonreference v0.19.3 h1:5cxNfTy0UVC3X8JL5ymxzyoUZmo8iZb+jeTWn7tUa8o= github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8= github.com/go-openapi/loads v0.17.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU= github.com/go-openapi/loads v0.18.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU= @@ -179,7 +177,6 @@ github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dp github.com/go-openapi/swag v0.17.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg= github.com/go-openapi/swag v0.18.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg= github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= -github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= github.com/go-openapi/validate v0.18.0/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+MYsct2VUrAJ4= github.com/go-openapi/validate v0.19.2/go.mod h1:1tRCw7m3jtI8eNWEEliiAqUIcBztB2KDnRCRMUi7GTA= @@ -307,7 +304,6 @@ github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mailru/easyjson v0.7.0 h1:aizVhC/NAAcKWb+5QsU1iNOZb4Yws5UO2I+aIprQITM= github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= @@ -357,7 +353,6 @@ github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/9 github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= diff --git a/api/v2beta1/helmrelease_types.go b/api/v2beta1/helmrelease_types.go index afc1485cd..11f590675 100644 --- a/api/v2beta1/helmrelease_types.go +++ b/api/v2beta1/helmrelease_types.go @@ -25,6 +25,7 @@ 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" ) @@ -32,15 +33,6 @@ import ( 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. @@ -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. diff --git a/api/v2beta1/kustomization_types.go b/api/v2beta1/kustomization_types.go deleted file mode 100644 index 9f480a892..000000000 --- a/api/v2beta1/kustomization_types.go +++ /dev/null @@ -1,65 +0,0 @@ -/* -Copyright 2020 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 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"` -} diff --git a/api/v2beta1/zz_generated.deepcopy.go b/api/v2beta1/zz_generated.deepcopy.go index 96d4a8956..cd64b6346 100644 --- a/api/v2beta1/zz_generated.deepcopy.go +++ b/api/v2beta1/zz_generated.deepcopy.go @@ -1,7 +1,7 @@ // +build !ignore_autogenerated /* -Copyright 2020 The Flux authors +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. @@ -21,6 +21,7 @@ limitations under the License. package v2beta1 import ( + "github.com/fluxcd/pkg/apis/kustomize" "github.com/fluxcd/pkg/runtime/dependency" "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -42,21 +43,6 @@ func (in *CrossNamespaceObjectReference) DeepCopy() *CrossNamespaceObjectReferen return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Gvk) DeepCopyInto(out *Gvk) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Gvk. -func (in *Gvk) DeepCopy() *Gvk { - if in == nil { - return nil - } - out := new(Gvk) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *HelmChartTemplate) DeepCopyInto(out *HelmChartTemplate) { *out = *in @@ -255,21 +241,6 @@ func (in *HelmReleaseStatus) DeepCopy() *HelmReleaseStatus { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Image) DeepCopyInto(out *Image) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Image. -func (in *Image) DeepCopy() *Image { - if in == nil { - return nil - } - out := new(Image) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Install) DeepCopyInto(out *Install) { *out = *in @@ -348,14 +319,14 @@ func (in *Kustomize) DeepCopyInto(out *Kustomize) { } if in.PatchesJSON6902 != nil { in, out := &in.PatchesJSON6902, &out.PatchesJSON6902 - *out = make([]PatchJSON6902, len(*in)) + *out = make([]kustomize.JSON6902Patch, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } if in.Images != nil { in, out := &in.Images, &out.Images - *out = make([]Image, len(*in)) + *out = make([]kustomize.Image, len(*in)) copy(*out, *in) } } @@ -370,29 +341,6 @@ func (in *Kustomize) DeepCopy() *Kustomize { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PatchJSON6902) DeepCopyInto(out *PatchJSON6902) { - *out = *in - if in.Patch != nil { - in, out := &in.Patch, &out.Patch - *out = make([]v1.JSON, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - out.Target = in.Target -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PatchJSON6902. -func (in *PatchJSON6902) DeepCopy() *PatchJSON6902 { - if in == nil { - return nil - } - out := new(PatchJSON6902) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PostRenderer) DeepCopyInto(out *PostRenderer) { *out = *in @@ -433,22 +381,6 @@ func (in *Rollback) DeepCopy() *Rollback { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Selector) DeepCopyInto(out *Selector) { - *out = *in - out.Gvk = in.Gvk -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Selector. -func (in *Selector) DeepCopy() *Selector { - if in == nil { - return nil - } - out := new(Selector) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Test) DeepCopyInto(out *Test) { *out = *in diff --git a/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml b/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml index 08106de1c..51e9b3815 100644 --- a/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml +++ b/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml @@ -250,22 +250,46 @@ 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 @@ -273,8 +297,16 @@ spec: 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 @@ -282,12 +314,21 @@ spec: 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: diff --git a/controllers/helmrelease_types_test.go b/controllers/helmrelease_types_test.go index ab50e4733..ac2d7d65a 100644 --- a/controllers/helmrelease_types_test.go +++ b/controllers/helmrelease_types_test.go @@ -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) diff --git a/docs/api/helmrelease.md b/docs/api/helmrelease.md index 431355bbe..2b4d52fca 100644 --- a/docs/api/helmrelease.md +++ b/docs/api/helmrelease.md @@ -422,58 +422,6 @@ string

DeploymentAction

DeploymentAction defines a consistent interface for Install and Upgrade.

-

Gvk -

-

-(Appears on: -Selector) -

-

Gvk identifies a Kubernetes API type. -https://github.com/kubernetes/community/blob/master/contributors/design-proposals/api-machinery/api-group.md

-
-
- - - - - - - - - - - - - - - - - - - - - -
FieldDescription
-group
- -string - -
-
-version
- -string - -
-
-kind
- -string - -
-
-
-

HelmChartTemplate

@@ -1114,73 +1062,6 @@ state. It is reset after a successful reconciliation.

-

Image -

-

-(Appears on: -Kustomize) -

-

Image contains an image name, a new name, a new tag or digest, -which will replace the original name and tag.

-
-
- - - - - - - - - - - - - - - - - - - - - - - - - -
FieldDescription
-name
- -string - -
-

Name is a tag-less image name.

-
-newName
- -string - -
-

NewName is the value used to replace the original name.

-
-newTag
- -string - -
-

NewTag is the value used to replace the original tag.

-
-digest
- -string - -
-

Digest is the value used to replace the original image tag. -If digest is present NewTag value is ignored.

-
-
-

Install

@@ -1450,8 +1331,8 @@ the HelmRelease.

patchesJson6902
- -[]PatchJSON6902 + +[]github.com/fluxcd/pkg/apis/kustomize.JSON6902Patch @@ -1464,8 +1345,8 @@ the HelmRelease.

images
- -[]Image + +[]github.com/fluxcd/pkg/apis/kustomize.Image @@ -1480,53 +1361,6 @@ patch, but this operator is simpler to specify.

-

PatchJSON6902 -

-

-(Appears on: -Kustomize) -

-

PatchJSON6902 contains a JSON patch and the target it applies to.

-
-
- - - - - - - - - - - - - - - - - -
FieldDescription
-patch
- - -[]Kubernetes pkg/apis/apiextensions/v1.JSON - - -
-

Patch is the YAML content of a patch.

-
-target
- - -Selector - - -
-

Target points to the resources that the patch is applied to.

-
-
-

PostRenderer

@@ -1674,90 +1508,6 @@ rollback action when it fails.

-

Selector -

-

-(Appears on: -PatchJSON6902) -

-

Selector specifies a set of resources. -Any resource that matches intersection of all conditions -is included in this set.

-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FieldDescription
-Gvk
- - -Gvk - - -
-

-(Members of Gvk are embedded into this type.) -

-
-namespace
- -string - -
-
-name
- -string - -
-
-annotationSelector
- -string - -
-

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.

-
-labelSelector
- -string - -
-

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.

-
-
-

Test

diff --git a/docs/spec/v2beta1/helmreleases.md b/docs/spec/v2beta1/helmreleases.md index 1c320fe59..d7bd16a56 100644 --- a/docs/spec/v2beta1/helmreleases.md +++ b/docs/spec/v2beta1/helmreleases.md @@ -365,15 +365,6 @@ type Uninstall struct { KeepHistory bool `json:"keepHistory,omitempty"` } -// 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. @@ -382,13 +373,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. @@ -1082,11 +1073,11 @@ spec: namespace: kube-system interval: 1m postRenderers: - # instruct helm-controller to use built-in "kustomize" post renderer. - - kustomize: - # Array of inline strategic merge patch definitions as YAML object. - # Note, this is a YAML object and not a string, to avoid syntax - # indention errors. + # Instruct helm-controller to use built-in "kustomize" post renderer. + - kustomize: + # Array of inline strategic merge patch definitions as YAML object. + # Note, this is a YAML object and not a string, to avoid syntax + # indention errors. patchesStrategicMerge: - kind: Deployment apiVersion: apps/v1 @@ -1099,24 +1090,23 @@ spec: - key: "workload-type" operator: "Equal" value: "cluster-services" - effect: "NoSchedule" - # Array of inline JSON6902 patch definitions as YAML object. - # Note, this is a YAML object and not a string, to avoid syntax - # indention errors. - patchesJson6902: - - target: - version: v1 - kind: Deployment - name: metrics-server - patch: - - op: add - path: /spec/template/priorityClassName - value: system-cluster-critical - images: - - name: docker.io/bitnami/metrics-server - newName: docker.io/bitnami/metrics-server - newTag: 0.4.1-debian-10-r54 - + effect: "NoSchedule" + # Array of inline JSON6902 patch definitions as YAML object. + # Note, this is a YAML object and not a string, to avoid syntax + # indention errors. + patchesJson6902: + - target: + version: v1 + kind: Deployment + name: metrics-server + patch: + - op: add + path: /spec/template/priorityClassName + value: system-cluster-critical + images: + - name: docker.io/bitnami/metrics-server + newName: docker.io/bitnami/metrics-server + newTag: 0.4.1-debian-10-r54 ``` ## Status diff --git a/go.mod b/go.mod index 7d54aff6d..12702883d 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ replace github.com/fluxcd/helm-controller/api => ./api require ( github.com/fluxcd/helm-controller/api v0.6.1 + github.com/fluxcd/pkg/apis/kustomize v0.0.1 github.com/fluxcd/pkg/apis/meta v0.7.0 github.com/fluxcd/pkg/runtime v0.8.0 github.com/fluxcd/source-controller/api v0.7.0 diff --git a/go.sum b/go.sum index c25025bd1..a6f91aaed 100644 --- a/go.sum +++ b/go.sum @@ -241,6 +241,8 @@ github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZM github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc= github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fluxcd/pkg/apis/kustomize v0.0.1 h1:TkA80R0GopRY27VJqzKyS6ifiKIAfwBd7OHXtV3t2CI= +github.com/fluxcd/pkg/apis/kustomize v0.0.1/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= @@ -316,7 +318,6 @@ github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nA github.com/go-openapi/spec v0.17.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI= github.com/go-openapi/spec v0.18.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI= github.com/go-openapi/spec v0.19.2/go.mod h1:sCxk3jxKgioEJikev4fgkNmwS+3kuYdJtcsZsD5zxMY= -github.com/go-openapi/spec v0.19.3 h1:0XRyw8kguri6Yw4SxhsQA/atC88yqrk0+G4YhI2wabc= github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo= github.com/go-openapi/spec v0.19.5 h1:Xm0Ao53uqnk9QE/LlYV5DEU09UAgpliA85QoT9LzqPw= github.com/go-openapi/spec v0.19.5/go.mod h1:Hm2Jr4jv8G1ciIAo+frC/Ft+rR2kQDh8JHKHb3gWUSk= @@ -595,12 +596,10 @@ github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7 github.com/markbates/pkger v0.17.1/go.mod h1:0JoVlrol20BSywW79rN3kdFFsE5xYM+rSCQDXbLhiuI= github.com/marstr/guid v1.1.0/go.mod h1:74gB1z2wpxxInTG6yaqA7KrtM0NZ+RbrcqDvYHefzho= github.com/matoous/godox v0.0.0-20190911065817-5d6d842e92eb/go.mod h1:1BELzlh859Sh1c6+90blK8lbYy0kwQf1bYlBhBysy1s= -github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= diff --git a/hack/api-docs/config.json b/hack/api-docs/config.json index 489d1c58b..7971323ac 100644 --- a/hack/api-docs/config.json +++ b/hack/api-docs/config.json @@ -23,6 +23,10 @@ "typeMatchPrefix": "^github.com/fluxcd/pkg/runtime/dependency\\.CrossNamespaceDependencyReference$", "docsURLTemplate": "https://godoc.org/github.com/fluxcd/pkg/runtime/dependency#CrossNamespaceDependencyReference" }, + { + "typeMatchPrefix": "^github.com/fluxcd/pkg/apis/kustomize", + "docsURLTemplate": "https://godoc.org/github.com/fluxcd/pkg/apis/kustomize#{{ .TypeIdentifier }}" + }, { "typeMatchPrefix": "^github.com/fluxcd/pkg/apis/meta", "docsURLTemplate": "https://godoc.org/github.com/fluxcd/pkg/apis/meta#{{ .TypeIdentifier }}" @@ -37,6 +41,7 @@ "k8s.io/apimachinery/pkg/apis/": "Kubernetes ", "k8s.io/apiextensions-apiserver/": "Kubernetes ", "github.com/fluxcd/pkg/runtime/": "Runtime ", + "github.com/fluxcd/pkg/apis/kustomize/": "Kustomize ", "github.com/fluxcd/pkg/apis/meta/": "Meta " }, "markdownDisabled": false diff --git a/hack/boilerplate.go.txt b/hack/boilerplate.go.txt index 681f77593..439ccd868 100644 --- a/hack/boilerplate.go.txt +++ b/hack/boilerplate.go.txt @@ -1,5 +1,5 @@ /* -Copyright 2020 The Flux authors +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. diff --git a/internal/runner/post_renderer.go b/internal/runner/post_renderer.go index 239bbf123..45ad3c501 100644 --- a/internal/runner/post_renderer.go +++ b/internal/runner/post_renderer.go @@ -1,3 +1,19 @@ +/* +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 runner import ( diff --git a/internal/runner/post_renderer_kustomize.go b/internal/runner/post_renderer_kustomize.go index 4945bfdfb..cc43ec0b1 100644 --- a/internal/runner/post_renderer_kustomize.go +++ b/internal/runner/post_renderer_kustomize.go @@ -1,14 +1,33 @@ +/* +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 runner import ( "bytes" "encoding/json" - v2 "github.com/fluxcd/helm-controller/api/v2beta1" "sigs.k8s.io/kustomize/api/filesys" "sigs.k8s.io/kustomize/api/konfig" "sigs.k8s.io/kustomize/api/krusty" kustypes "sigs.k8s.io/kustomize/api/types" + + "github.com/fluxcd/pkg/apis/kustomize" + + v2 "github.com/fluxcd/helm-controller/api/v2beta1" ) type postRendererKustomize struct { @@ -45,7 +64,7 @@ func writeFile(fs filesys.FileSystem, path string, content *bytes.Buffer) error return nil } -func adaptImages(images []v2.Image) (output []kustypes.Image) { +func adaptImages(images []kustomize.Image) (output []kustypes.Image) { for _, image := range images { output = append(output, kustypes.Image{ Name: image.Name, @@ -57,12 +76,12 @@ func adaptImages(images []v2.Image) (output []kustypes.Image) { return } -func adaptSelector(selector *v2.Selector) (output *kustypes.Selector) { +func adaptSelector(selector *kustomize.Selector) (output *kustypes.Selector) { if selector != nil { output = &kustypes.Selector{} - output.Gvk.Group = selector.Gvk.Group - output.Gvk.Kind = selector.Gvk.Kind - output.Gvk.Version = selector.Gvk.Version + output.Gvk.Group = selector.Group + output.Gvk.Kind = selector.Kind + output.Gvk.Version = selector.Version output.Name = selector.Name output.Namespace = selector.Namespace output.LabelSelector = selector.LabelSelector diff --git a/internal/runner/runner.go b/internal/runner/runner.go index c4c58ad82..376cfcd20 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -1,5 +1,5 @@ /* -Copyright 2020 The Flux authors +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.