Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate CRDs #182

Merged
merged 1 commit into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ 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
CRD_SOURCES = $(shell find pkg/apis/zalando.org -name '*.go')
GENERATED_CRDS = docs/stackset_crd.yaml docs/stack_crd.yaml
GENERATED = pkg/apis/zalando.org/v1/zz_generated.deepcopy.go
CONTROLLER_GEN = ./build/controller-gen
GOPKGS = $(shell go list ./... | grep -v /e2e | grep -v vendor)
BUILD_FLAGS ?= -v
LDFLAGS ?= -X main.version=$(VERSION) -w -s
Expand All @@ -19,6 +22,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 +34,20 @@ 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: $(GENERATED_CRDS)

$(GENERATED_CRDS): $(CONTROLLER_GEN) $(GENERATED) $(CRD_SOURCES)
$(CONTROLLER_GEN) crd:preserveUnknownFields=false paths=./pkg/apis/... output:crd:dir=docs || /bin/true || true
mv docs/zalando.org_stacksets.yaml docs/stackset_crd.yaml
mv docs/zalando.org_stacks.yaml docs/stack_crd.yaml
# workaround for CRD issue with k8s 1.18 & controller-gen 0.3
# ref: https://github.com/kubernetes/kubernetes/issues/91395
perl -i -p0e 's/\s*x-kubernetes-list-map-keys:.*?x-kubernetes-list-type: map//seg' $(GENERATED_CRDS)

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

Expand Down
178 changes: 70 additions & 108 deletions docs/stack_crd.yaml

Large diffs are not rendered by default.

191 changes: 65 additions & 126 deletions docs/stackset_crd.yaml

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@ go 1.13
require (
github.com/alecthomas/kingpin v2.2.6+incompatible
github.com/emicklei/go-restful v2.11.1+incompatible // indirect
github.com/fatih/color v1.9.0 // indirect
github.com/go-openapi/spec v0.19.4 // indirect
github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7 // indirect
github.com/google/go-cmp v0.5.1
github.com/googleapis/gnostic v0.2.0 // indirect
github.com/heptiolabs/healthcheck v0.0.0-20180807145615-6ff867650f40
github.com/imdario/mergo v0.3.6 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/prometheus/client_golang v1.7.1
github.com/sirupsen/logrus v1.6.0
github.com/stretchr/testify v1.6.1
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa // indirect
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
golang.org/x/tools v0.0.0-20191210221141-98df12377212 // indirect
golang.org/x/tools v0.0.0-20200123022218-593de606220b // indirect
gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0 // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6
k8s.io/api v0.18.8
k8s.io/apimachinery v0.18.8
k8s.io/client-go v0.18.8
k8s.io/code-generator v0.18.8
sigs.k8s.io/controller-tools v0.3.0
)
244 changes: 199 additions & 45 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
40 changes: 35 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="Stacks",type=integer,JSONPath=`.status.stacks`,description="Number of Stacks belonging to the StackSet"
// +kubebuilder:printcolumn:name="Ready",type=integer,JSONPath=`.status.readyStacks`,description="Number of Ready Stacks"
// +kubebuilder:printcolumn:name="Traffic",type=integer,JSONPath=`.status.stacksWithTraffic`,description="Number of Ready Stacks with traffic"
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`,description="Age of the stack"
// +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=float
// +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=float
Copy link
Contributor

@muaazsaleem muaazsaleem Aug 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Is this deliberately not float64? i.e // +kubebuilder:validation:Format=float64

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nvm, I see here that it's not a valid format.

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=integer,JSONPath=`.spec.replicas`,description="Number of desired replicas"
// +kubebuilder:printcolumn:name="Current",type=integer,JSONPath=`.status.replicas`,description="Number of current replicas"
// +kubebuilder:printcolumn:name="Up-To-Date",type=integer,JSONPath=`.status.updatedReplicas`,description="Number of up-to-date replicas"
// +kubebuilder:printcolumn:name="Ready",type=integer,JSONPath=`.status.readyReplicas`,description="Number of ready replicas"
// +kubebuilder:printcolumn:name="Traffic",type=number,JSONPath=`.status.actualTrafficWeight`,description="Current traffic weight for the stack"
// +kubebuilder:printcolumn:name="No-Traffic-Since",type=date,JSONPath=`.status.noTrafficSince`,description="Time since the stack didn't get any traffic"
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`,description="Age of the stack"
// +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 All @@ -263,10 +287,14 @@ type StackStatus struct {
// routed to the stack.
// TODO: should we be using floats in the API?
// +optional
// +kubebuilder:validation:Format=float
// +kubebuilder:validation:Type=number
ActualTrafficWeight float64 `json:"actualTrafficWeight"`
// DesiredTrafficWeight is desired amount of traffic to be routed to
// the stack.
// +optional
// +kubebuilder:validation:Format=float
// +kubebuilder:validation:Type=number
DesiredTrafficWeight float64 `json:"desiredTrafficWeight"`
// Replicas is the number of replicas in the Deployment managed by the
// stack.
Expand Down Expand Up @@ -305,6 +333,8 @@ type PrescalingStatus struct {
Replicas int32 `json:"replicas,omitempty"`
// DesiredTrafficWeight is the desired traffic weight that the stack was prescaled for
// +optional
// +kubebuilder:validation:Format=float
// +kubebuilder:validation:Type=number
DesiredTrafficWeight float64 `json:"desiredTrafficWeight,omitempty"`
// LastTrafficIncrease is the timestamp when the traffic was last increased on the stack
// +optional
Expand Down