Skip to content

Commit

Permalink
add first version of x-kuberneets impl with unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dbadura committed Oct 5, 2023
1 parent acfc0eb commit 779b62f
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 325 deletions.
3 changes: 3 additions & 0 deletions components/serverless/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ vendor/
cover.out
filered.cov
log_config.yaml

# Directory with temporary files used to do development
hack/test_files
10 changes: 4 additions & 6 deletions components/serverless/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ override VERIFY_IGNORE := /vendor\|/automock\|/pkg/apis/serverless/v1alpha2/zz_g
# Image URL to use all building/pushing image targets
IMG ?= $(APP_NAME):latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true,crdVersions=v1"
#CRD_OPTIONS ?= "crd:trivialVersions=true,crdVersions=v1"

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand All @@ -31,19 +31,17 @@ test-local:
@go tool cover -func=/tmp/artifacts/cover.out | grep total | awk '{print $$3}'

# Generate manifests e.g. CRD, RBAC etc.
CONTROLLER_GEN_VERSION=v0.6.2
CONTROLLER_GEN_VERSION=v0.9.2

.PHONY: manifests
manifests: controller-gen-local generate-local
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=serverless webhook paths="./..." \
$(CONTROLLER_GEN) rbac:roleName=serverless crd webhook paths="./..." \
object:headerFile=hack/boilerplate.go.txt \
output:crd:artifacts:config=config/crd/bases \
output:rbac:artifacts:config=config/rbac \
output:webhook:artifacts:config=config/webhook
kustomize build config/crd > config/crd/crd-serverless.yaml
cp config/crd/crd-serverless.yaml ../../installation/resources/crds/serverless/
cp config/crd/crd-serverless.yaml ../../resources/serverless/templates/crds.yaml
(cd ../../hack/table-gen && make serverless-docs )
#(cd ../../hack/table-gen && make serverless-docs )

# Generate code
.PHONY: generate-local
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.2
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: functions.serverless.kyma-project.io
spec:
Expand Down Expand Up @@ -68,6 +67,9 @@ spec:
description: Defines annotations used in Deployment's PodTemplate
and applied on the Function's runtime Pod.
type: object
x-kubernetes-validations:
- message: Labels has key starting with serverless.kyma-project.io/
rule: '!(self.exists(e, e.matches(''serverless.kyma-project.io/*'')))'
env:
description: Specifies an array of key-value pairs to be used as environment
variables for the Function. You can define values as static strings
Expand Down Expand Up @@ -112,6 +114,7 @@ spec:
required:
- key
type: object
x-kubernetes-map-type: atomic
fieldRef:
description: 'Selects a field of the pod: supports metadata.name,
metadata.namespace, `metadata.labels[''<KEY>'']`, `metadata.annotations[''<KEY>'']`,
Expand All @@ -129,6 +132,7 @@ spec:
required:
- fieldPath
type: object
x-kubernetes-map-type: atomic
resourceFieldRef:
description: 'Selects a resource of the container: only
resources limits and requests (limits.cpu, limits.memory,
Expand All @@ -153,6 +157,7 @@ spec:
required:
- resource
type: object
x-kubernetes-map-type: atomic
secretKeyRef:
description: Selects a key of a secret in the pod's namespace
properties:
Expand All @@ -171,6 +176,7 @@ spec:
required:
- key
type: object
x-kubernetes-map-type: atomic
type: object
required:
- name
Expand All @@ -182,6 +188,9 @@ spec:
description: Defines labels used in Deployment's PodTemplate and applied
on the Function's runtime Pod.
type: object
x-kubernetes-validations:
- message: Labels has key starting with serverless.kyma-project.io/
rule: '!(self.exists(e, e.matches(''serverless.kyma-project.io/*'')))'
replicas:
default: 1
description: Defines the exact number of Function's Pods to run at
Expand Down Expand Up @@ -234,6 +243,10 @@ spec:
type: object
type: object
type: object
x-kubernetes-validations:
- message: Profile or resources
rule: has(self.profile) && !has(self.resources) || !has(self.profile)
&& has(self.resources)
function:
description: Specifies resources requested by the Function's Pod.
properties:
Expand Down Expand Up @@ -271,6 +284,10 @@ spec:
type: object
type: object
type: object
x-kubernetes-validations:
- message: Profile or resources
rule: has(self.profile) && !has(self.resources) || !has(self.profile)
&& has(self.resources)
type: object
runtime:
description: Specifies the runtime of the Function. The available
Expand Down Expand Up @@ -480,9 +497,3 @@ spec:
specReplicasPath: .spec.replicas
statusReplicasPath: .status.replicas
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
1 change: 0 additions & 1 deletion components/serverless/config/rbac/role.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down
1 change: 0 additions & 1 deletion components/serverless/config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
Expand Down
64 changes: 37 additions & 27 deletions components/serverless/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,35 @@ replace (
golang.org/x/crypto => golang.org/x/crypto v0.0.0-20220213190939-1e6e3497d506
golang.org/x/oauth2 => golang.org/x/oauth2 v0.6.0
gopkg.in/yaml.v2 => gopkg.in/yaml.v2 v2.3.0
k8s.io/api => k8s.io/api v0.22.7
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.22.7
k8s.io/apimachinery => k8s.io/apimachinery v0.22.15
k8s.io/client-go => k8s.io/client-go v0.22.7
k8s.io/component-base => k8s.io/component-base v0.22.7
k8s.io/api => k8s.io/api v0.25.13
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.25.13
k8s.io/apimachinery => k8s.io/apimachinery v0.25.13
k8s.io/client-go => k8s.io/client-go v0.25.13
k8s.io/component-base => k8s.io/component-base v0.25.13
)

require (
github.com/fsnotify/fsnotify v1.5.1
github.com/go-logr/zapr v1.2.0
github.com/go-logr/zapr v1.2.3
github.com/kyma-project/kyma/common/logging v0.0.0-20221208072023-1c1502074930
github.com/libgit2/git2go/v34 v34.0.0
github.com/onsi/gomega v1.17.0
github.com/onsi/gomega v1.20.1
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.11.1
github.com/prometheus/client_golang v1.12.1
github.com/prometheus/common v0.32.1 // indirect
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.7.0
github.com/stretchr/objx v0.4.0 // indirect
github.com/stretchr/testify v1.8.0
github.com/vrischmann/envconfig v1.3.0
go.uber.org/zap v1.21.0
golang.org/x/crypto v0.0.0-20220214200702-86341886e292
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.24.0
k8s.io/apiextensions-apiserver v0.24.0
k8s.io/apimachinery v0.24.0
k8s.io/client-go v0.23.5
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
sigs.k8s.io/controller-runtime v0.11.2
k8s.io/api v0.25.13
k8s.io/apiextensions-apiserver v0.24.2
k8s.io/apimachinery v0.25.13
k8s.io/client-go v0.25.13
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed
sigs.k8s.io/controller-runtime v0.12.3
)

require (
Expand All @@ -50,33 +50,42 @@ require (
require (
cloud.google.com/go v0.98.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/moby/term v0.0.0-20210610120745-9d4ed1856297 // indirect
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/image-spec v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/atomic v1.9.0 // indirect
Expand All @@ -91,10 +100,11 @@ require (
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/component-base v0.23.5 // indirect
k8s.io/klog/v2 v2.60.1 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/component-base v0.25.13 // indirect
k8s.io/klog/v2 v2.70.1 // indirect
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit 779b62f

Please sign in to comment.