Skip to content

Commit

Permalink
Generate CRDs using controller-gen
Browse files Browse the repository at this point in the history
Signed-off-by: Arjun Naik <arjun@arjunnaik.in>
  • Loading branch information
arjunrn committed Dec 19, 2019
1 parent b046043 commit 713da1f
Show file tree
Hide file tree
Showing 8 changed files with 10,477 additions and 585 deletions.
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

BINARY = stackset-controller
BINARIES = $(BINARY) traffic
CONTROLLER_GEN = ./build/controller-gen
LOCAL_BINARIES = $(addprefix build/,$(BINARIES))
LINUX_BINARIES = $(addprefix build/linux/,$(BINARIES))
GO ?= go
VERSION ?= $(shell git describe --tags --always --dirty)
IMAGE ?= registry-write.opensource.zalan.do/teapot/$(BINARY)
E2E_IMAGE ?= $(IMAGE)-e2e
TAG ?= $(VERSION)
SOURCES = $(shell find . -name '*.go')
GENERATED = pkg/client pkg/apis/zalando.org/v1/zz_generated.deepcopy.go
GENERATED_CRDS = $(shell find ./docs -name 'stack*_crd.yaml')
CRD_SOURCES = $(shell find pkg/apis/zalando.org -name '*.go')
GENERATED = pkg/apis/zalando.org/v1/zz_generated.deepcopy.go
GOPKGS = $(shell go list ./... | grep -v /e2e | grep -v vendor)
BUILD_FLAGS ?= -v
LDFLAGS ?= -X main.version=$(VERSION) -w -s
Expand All @@ -19,6 +23,7 @@ default: build.local
clean:
rm -rf build
rm -rf $(GENERATED)
rm -f $(GENERATED_CRDS)

test: $(GENERATED)
go test -v $(GOPKGS)
Expand All @@ -30,6 +35,17 @@ check: $(GENERATED)
$(GENERATED):
./hack/update-codegen.sh

$(CONTROLLER_GEN):
mkdir -p build
GOBIN=$(shell pwd)/build $(GO) install sigs.k8s.io/controller-tools/cmd/controller-gen

crds: $(CONTROLLER_GEN) $(SOURCES)
mkdir -p $@
$(CONTROLLER_GEN) crd paths=./pkg/apis/... output:crd:dir=$@ || /bin/true
mv $@/zalando.org_stacksets.yaml ./docs/stackset_crd.yaml
mv $@/zalando.org_stacks.yaml ./docs/stack_crd.yaml
rm -rf $@

build.local: $(LOCAL_BINARIES)
build.linux: $(LINUX_BINARIES)

Expand Down
5,111 changes: 4,839 additions & 272 deletions docs/stack_crd.yaml

Large diffs are not rendered by default.

5,770 changes: 5,463 additions & 307 deletions docs/stackset_crd.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ require (
k8s.io/client-go v0.0.0-20191202165906-e3970fe37d8a
k8s.io/code-generator v0.0.0-20191004115455-8e001e5d1894
k8s.io/gengo v0.0.0-20191120174120-e74f70b9b27e // indirect
sigs.k8s.io/controller-tools v0.2.4
)
124 changes: 124 additions & 0 deletions go.sum

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions hack/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ limitations under the License.
package tools

import _ "k8s.io/code-generator"
import _ "sigs.k8s.io/controller-tools/cmd/controller-gen"
3 changes: 3 additions & 0 deletions pkg/apis/zalando.org/v1/register.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Package v1 contains API Schema definitions for the zalando v1 API group
// +kubebuilder:object:generate=true
// +groupName=zalando.org
package v1

import (
Expand Down
34 changes: 29 additions & 5 deletions pkg/apis/zalando.org/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ import (

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true

// StackSet describes an application resource.
// +k8s:deepcopy-gen=true
// +kubebuilder:printcolumn:name="Desired",type=string,JSONPath=`.status.stacks`
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.readyStacks`
// +kubebuilder:printcolumn:name="Traffic",type=string,JSONPath=`.status.stacksWithTraffic`
// +kubebuilder:printcolumn:name="Age",type=string,JSONPath=`.metadata.creationTimestamp`
// +kubebuilder:subresource:status
type StackSet struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down Expand Up @@ -52,7 +58,8 @@ type StackSetIngressSpec struct {
metav1.ObjectMeta `json:"metadata,omitempty"`
Hosts []string `json:"hosts"`
BackendPort intstr.IntOrString `json:"backendPort"`
Path string `json:"path"`
// +optional
Path string `json:"path"`
}

// StackSetExternalIngressSpec defines the required service
Expand All @@ -73,6 +80,7 @@ type StackLifecycle struct {
// Limit defines the maximum number of Stacks to keep around. If the
// number of Stacks exceeds the limit then the oldest stacks which are
// not getting traffic are deleted.
// +kubebuilder:validation:Minimum=1
Limit *int32 `json:"limit,omitempty"`
}

Expand Down Expand Up @@ -179,19 +187,25 @@ type ActualTraffic struct {
StackName string `json:"stackName"`
ServiceName string `json:"serviceName"`
ServicePort intstr.IntOrString `json:"servicePort"`
Weight float64 `json:"weight"`

// +kubebuilder:validation:Format=float64
// +kubebuilder:validation:Type=number
Weight float64 `json:"weight"`
}

// DesiredTraffic is the desired traffic setting to direct traffic to
// a stack. This is meant to use by clients to orchestrate traffic
// switching.
type DesiredTraffic struct {
StackName string `json:"stackName"`
Weight float64 `json:"weight"`
StackName string `json:"stackName"`
// +kubebuilder:validation:Type=number
// +kubebuilder:validation:Format=float64
Weight float64 `json:"weight"`
}

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

// +kubebuilder:object:root=true
// StackSetList is a list of StackSets.
// +k8s:deepcopy-gen=true
type StackSetList struct {
Expand All @@ -207,6 +221,15 @@ type StackSetList struct {
// Stack defines one version of an application. It is possible to
// switch traffic between multiple versions of an application.
// +k8s:deepcopy-gen=true
// +kubebuilder:printcolumn:name="Desired",type=string,JSONPath=`.spec.replicas`
// +kubebuilder:printcolumn:name="Current",type=string,JSONPath=`.status.replicas`
// +kubebuilder:printcolumn:name="Up-To-Date",type=string,JSONPath=`.status.updatedReplicas`
// +kubebuilder:printcolumn:name="Ready Replicas",type=string,JSONPath=`.status.readyReplicas`
// +kubebuilder:printcolumn:name="Traffic",type=string,JSONPath=`.status.actualTrafficWeight`
// +kubebuilder:printcolumn:name="No-Traffic-Since",type=string,JSONPath=`.status.noTrafficSince`
// +kubebuilder:printcolumn:name="Age",type=string,JSONPath=`.metadata.creationTimestamp`
// +kubebuilder:subresource:status
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.labelSelector
type Stack struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down Expand Up @@ -252,7 +275,8 @@ type StackServiceSpec struct {
// StackSpecTemplate is the spec part of the Stack.
// +k8s:deepcopy-gen=true
type StackSpecTemplate struct {
StackSpec
StackSpec `json:",inline"`
// +kubebuilder:validation:Pattern="^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$"
Version string `json:"version"`
}

Expand Down

0 comments on commit 713da1f

Please sign in to comment.