Skip to content

Commit

Permalink
feat: Ship CRD's manifests also in version v1beta1 for kubernetes 1.15
Browse files Browse the repository at this point in the history
and older

Signed-off-by: grzesuav <grzesuav@gmail.com>
  • Loading branch information
grzesuav committed Jan 25, 2021
1 parent a4c2156 commit 284b3e2
Show file tree
Hide file tree
Showing 13 changed files with 1,158 additions and 631 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,3 +7,4 @@
**/.vscode
**/.venv
docs/book
tmp
27 changes: 25 additions & 2 deletions Makefile
Expand Up @@ -8,39 +8,59 @@ API_GROUPS := metacontroller/v1alpha1
export GO111MODULE=on
export GOTESTSUM_FORMAT=pkgname

CONTROLLER_GEN := go run ./vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go

all: install

install: generated_files
go install

.PHONY: vendor
vendor:
@go mod download
@go mod tidy
@go mod vendor

.PHONY: unit-test
unit-test: test-setup
pkgs="$$(go list ./... | grep -v '/test/integration/\|/examples/\|hack')" ; \
go test -i $${pkgs} && \
gotestsum $${pkgs}

.PHONY: integration-test
integration-test: test-setup
gotestsum ./test/integration/... -v -timeout 5m -args --logtostderr -v=1

.PHONY: test-setup
test-setup: vendor
./hack/setup.sh

.PHONY: image
image: generated_files
docker build -t metacontrollerio/metacontroller:$(TAG) .

push: image
docker push metacontrollerio/metacontroller:$(TAG)


# CRD generation
# rember to remove unnesessary metadata fields and
# add "api-approved.kubernetes.io": "unapproved, request not yet submitted"
# to annotations
.PHONY: generate_crds
generate_crds:
@echo "+ Generating crds"
@$(CONTROLLER_GEN) "crd:trivialVersions=true,crdVersions=v1beta1" rbac:roleName=manager-role paths="./apis/..." output:crd:artifacts:config=tmp/crds-v1beta1
@cat tmp/crds-v1beta1/*.yaml > manifests/production/metacontroller-crds-v1beta1.yaml
@$(CONTROLLER_GEN) "crd:trivialVersions=false,crdVersions=v1" rbac:roleName=manager-role paths="./apis/..." output:crd:artifacts:config=tmp/crds-v1
@cat tmp/crds-v1/*.yaml > manifests/production/metacontroller-crds-v1.yaml

# Code generators
# https://github.com/kubernetes/community/blob/master/contributors/devel/api_changes.md#generate-code

.PHONY: generated_files
generated_files: deepcopy clientset lister informer

# also builds vendored version of deepcopy-gen tool
.PHONY: deepcopy
deepcopy:
@go install ./vendor/k8s.io/code-generator/cmd/deepcopy-gen
@echo "+ Generating deepcopy funcs for $(API_GROUPS)"
Expand All @@ -49,6 +69,7 @@ deepcopy:
--output-file-base zz_generated.deepcopy

# also builds vendored version of client-gen tool
.PHONY: clientset
clientset:
@go install ./vendor/k8s.io/code-generator/cmd/client-gen
@echo "+ Generating clientsets for $(API_GROUPS)"
Expand All @@ -59,6 +80,7 @@ clientset:
--clientset-path $(PKG)/client/generated/clientset

# also builds vendored version of lister-gen tool
.PHONY: lister
lister:
@go install ./vendor/k8s.io/code-generator/cmd/lister-gen
@echo "+ Generating lister for $(API_GROUPS)"
Expand All @@ -67,6 +89,7 @@ lister:
--output-package $(PKG)/client/generated/lister

# also builds vendored version of informer-gen tool
.PHONY: informer
informer:
@go install ./vendor/k8s.io/code-generator/cmd/informer-gen
@echo "+ Generating informer for $(API_GROUPS)"
Expand Down
5 changes: 0 additions & 5 deletions apis/metacontroller/v1alpha1/types.go
Expand Up @@ -26,7 +26,6 @@ import (
// +genclient:noStatus
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// +kubebuilder:subresource:status
// +kubebuilder:resource:path=compositecontrollers,scope=Cluster,shortName=cc;cctl
type CompositeController struct {
Expand Down Expand Up @@ -130,7 +129,6 @@ type CompositeControllerStatus struct {
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type CompositeControllerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Expand All @@ -140,7 +138,6 @@ type CompositeControllerList struct {
// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// +kubebuilder:subresource:status
// +kubebuilder:resource:path=controllerrevisions,scope=Namespaced
type ControllerRevision struct {
Expand All @@ -158,7 +155,6 @@ type ControllerRevisionChildren struct {
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type ControllerRevisionList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Expand Down Expand Up @@ -225,7 +221,6 @@ type DecoratorControllerStatus struct {
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type DecoratorControllerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Expand Down
27 changes: 16 additions & 11 deletions docs/src/guide/install.md
Expand Up @@ -5,15 +5,14 @@ controllers or just to run third-party controllers that depend on it.

## Prerequisites

* Kubernetes v1.16
* Kubernetes v1.11+
* You should have `kubectl` available and configured to talk to the desired cluster.

### Running on kubernetes older than 1.16

Metacontroller *should* work fine (as for now - December 2020) running on 1.9+, as it does not have direct dependency on kubernetes API version.
In this case you should use [0.4.5](https://github.com/metacontroller/metacontroller/releases/tag/v0.4.5) release manifests, just put current (or any fixed) image version in `metacontroller.yaml`.
However there is no gurantee that this will work forever - the goal is to make it compatibile with supported kubernetes releases.
Please update your cluster in that case.
As metacontroller does not have direct dependency on kubernetes API
it have wide range of supported kubernetes versions.
However, to be able to install it on clusters older than 1.16, CRD with schema in version `v1beta1` must be used then.

### Grant yourself cluster-admin (GKE only)

Expand All @@ -30,17 +29,23 @@ Replace `<user>` and `<domain>` above based on the account you use to authentica
## Install Metacontroller

```sh
# Create metacontroller namespace.
kubectl create namespace metacontroller
# Create metacontroller service account and role/binding.
kubectl apply -f {{ site.repo_raw }}/manifests/metacontroller-rbac.yaml
# Create CRDs for Metacontroller APIs, and the Metacontroller StatefulSet.
kubectl apply -f {{ site.repo_raw }}/manifests/metacontroller.yaml
# Apply all set of production resources defined in kustomization.yaml in `production` directory .
kubectl apply -k {{ site.repo_raw }}/manifests/production

```

If you prefer to build and host your own images, please see the
[build instructions](../contrib/build.md) in the contributor guide.

If your `kubectl` version does does not support `-k` flag, please
install resources mentioned in `manifests/production/kustomization.yaml`
one by one manually with `kubectl apply -f {{filename}}` command.

**Compatibility note**
CRD's are shipped in two versions:
* `v1` - supposed to be used when your kubernetes cluster is 1.16+
* `v1beta1` otherwise

## Configuration

The Metacontroller server has a few settings that can be configured
Expand Down
16 changes: 8 additions & 8 deletions go.mod
Expand Up @@ -2,27 +2,27 @@ module metacontroller.io

// This denotes the minimum supported language version and
// should not include the patch version.
go 1.14
go 1.15

require (
github.com/go-logr/logr v0.3.0 // indirect
github.com/google/go-jsonnet v0.14.0
github.com/google/go-jsonnet v0.14.0 // test
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/prometheus/client_golang v1.9.0
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
golang.org/x/tools v0.0.0-20201120155355-20be4ac4bd6e // indirect
google.golang.org/protobuf v1.25.0 // indirect
k8s.io/api v0.17.17
k8s.io/apiextensions-apiserver v0.17.17
k8s.io/apimachinery v0.17.17
k8s.io/api v0.17.17 // test
k8s.io/apiextensions-apiserver v0.17.17 // test
k8s.io/apimachinery v0.17.17 // test
k8s.io/client-go v0.17.17
k8s.io/code-generator v0.17.17
k8s.io/code-generator v0.17.17 // test
k8s.io/component-base v0.17.17
k8s.io/gengo v0.0.0-20201113003025-83324d819ded // indirect
k8s.io/klog v1.0.0
k8s.io/klog v1.0.0 // test
k8s.io/klog/v2 v2.4.0
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f
sigs.k8s.io/controller-tools v0.2.4
sigs.k8s.io/controller-tools v0.2.9 // test
)

replace (
Expand Down

0 comments on commit 284b3e2

Please sign in to comment.