Skip to content

Commit

Permalink
Merge pull request #77 from fluxcd/kustomize-api
Browse files Browse the repository at this point in the history
Introduce Kustomize API group
  • Loading branch information
hiddeco authored Feb 3, 2021
2 parents 736039c + 0a3c4dd commit a77cc48
Show file tree
Hide file tree
Showing 7 changed files with 894 additions and 1 deletion.
29 changes: 28 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
VER?=0.0.1
MODULES=$(shell find . -mindepth 2 -maxdepth 4 -type f -name 'go.mod' | cut -c 3- | sed 's|/[^/]*$$||' | sort -u | tr / :)
targets=$(addprefix test-, $(MODULES))
root_dir=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

all:
$(MAKE) $(targets)
Expand All @@ -14,7 +22,10 @@ fmt-%:
vet-%:
cd $(subst :,/,$*); go vet ./...

test-%: tidy-% fmt-% vet-%
generate-%: controller-gen
cd $(subst :,/,$*); $(CONTROLLER_GEN) object:headerFile="$(root_dir)/hack/boilerplate.go.txt" paths="./..."

test-%: generate-% tidy-% fmt-% vet-%
cd $(subst :,/,$*); go test ./... -coverprofile cover.out

release-%:
Expand All @@ -24,3 +35,19 @@ release-%:
git pull
git tag "$(REL_PATH)/v$(VER)"
git push origin "$(REL_PATH)/v$(VER)"

# Find or download controller-gen
controller-gen:
ifeq (, $(shell which controller-gen))
@{ \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/[email protected] ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
20 changes: 20 additions & 0 deletions apis/kustomize/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
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 kustomize contains a selective set of Kustomize APIs for use by
// toolkit components.
// +kubebuilder:object:generate=true
package kustomize
5 changes: 5 additions & 0 deletions apis/kustomize/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/fluxcd/pkg/apis/kustomize

go 1.15

require k8s.io/apiextensions-apiserver v0.20.2
613 changes: 613 additions & 0 deletions apis/kustomize/go.sum

Large diffs are not rendered by default.

115 changes: 115 additions & 0 deletions apis/kustomize/kustomize_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
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 kustomize

import (
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
)

// 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.
// +required
Name string `json:"name"`

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

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

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

// Selector specifies a set of resources.
// Any resource that matches intersection of all conditions is included in this set.
type Selector struct {
// 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
// +optional
Group string `json:"group,omitempty"`

// 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
// +optional
Version string `json:"version,omitempty"`

// 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
// +optional
Kind string `json:"kind,omitempty"`

// Namespace to select resources from.
// +optional
Namespace string `json:"namespace,omitempty"`

// Name to match resources with.
// +optional
Name string `json:"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.
// +optional
AnnotationSelector string `json:"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.
// +optional
LabelSelector string `json:"labelSelector,omitempty"`
}

// JSON6902 is a JSON6902 operation object.
// https://tools.ietf.org/html/rfc6902#section-4
type JSON6902 struct {
// +kubebuilder:validation:Enum=test;remove;add;replace;move;copy
// +required
Op string `json:"op"`
// +required
Path string `json:"path"`
// +optional
From string `json:"from,omitempty"`
// +optional
Value *apiextensionsv1.JSON `json:"value,omitempty"`
}

// JSON6902Patch contains a JSON6902 patch and the target the patch
// should be applied to.
type JSON6902Patch struct {
// Patch contains the JSON6902 patch document with an array of
// operation objects.
// +required
Patch []JSON6902 `json:"patch"`

// Target points to the resources that the patch document should
// be applied to.
// +required
Target Selector `json:"target"`
}
98 changes: 98 additions & 0 deletions apis/kustomize/zz_generated.deepcopy.go

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

15 changes: 15 additions & 0 deletions hack/boilerplate.go.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
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.
*/

0 comments on commit a77cc48

Please sign in to comment.