Skip to content

Commit

Permalink
Bump ginkgo to v2 (#109)
Browse files Browse the repository at this point in the history
- Bump ginkto to v2
- Generate manfiests
  • Loading branch information
afritzler authored Aug 1, 2022
1 parent b41e57a commit f2729cc
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 132 deletions.
31 changes: 19 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@

# Image URL to use all building/pushing image targets
IMG ?= controller:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:generateEmbeddedObjectMeta=true"

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -37,9 +34,11 @@ help: ## Display this help.

##@ Development

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true webhook paths="./..." output:crd:artifacts:config=config/crd/bases

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

Expand All @@ -49,20 +48,21 @@ addlicense: ## Add license headers to all go files.
fmt: ## Run go fmt against code.
go fmt ./...

vet: ## Run go vet against code.
go vet ./...

.PHONY: checklicense
checklicense: ## Check that every file has a license header present.
find . -name '*.go' -exec go run github.com/google/addlicense -check -c 'OnMetal authors' {} +

lint: ## Lint code
golangci-lint run ./...

ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: manifests generate fmt checklicense ## Run tests.
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out

check: lint test ## Lint and run tests.
check: manifests generate addlicense lint test ## Lint and run tests.

##@ Build

Expand Down Expand Up @@ -95,12 +95,19 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi


CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
.PHONY: controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.7.0)
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.9.0)

KUSTOMIZE = $(shell pwd)/bin/kustomize
.PHONY: kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])

ENVTEST = $(shell pwd)/bin/setup-envtest
.PHONY: envtest
envtest: ## Download envtest-setup locally if necessary.
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
Expand Down
61 changes: 26 additions & 35 deletions config/crd/bases/matryoshka.onmetal.de_kubeapiservers.yaml
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.7.0
controller-gen.kubebuilder.io/version: v0.9.0
creationTimestamp: null
name: kubeapiservers.matryoshka.onmetal.de
spec:
Expand Down Expand Up @@ -3218,13 +3217,12 @@ spec:
when the pod is removed. \n Use this if: a) the volume
is only needed while the pod runs, b) features of
normal volumes like restoring from snapshot or capacity
\ tracking are needed, c) the storage driver is
specified through a storage class, and d) the storage
driver supports dynamic volume provisioning through
\ a PersistentVolumeClaim (see EphemeralVolumeSource
for more information on the connection between
this volume type and PersistentVolumeClaim). \n
Use PersistentVolumeClaim or one of the vendor-specific
tracking are needed, c) the storage driver is specified
through a storage class, and d) the storage driver
supports dynamic volume provisioning through a PersistentVolumeClaim
(see EphemeralVolumeSource for more information on
the connection between this volume type and PersistentVolumeClaim).
\n Use PersistentVolumeClaim or one of the vendor-specific
APIs for volumes that persist for longer than the
lifecycle of an individual pod. \n Use CSI for light-weight
local ephemeral volumes if the CSI driver is meant
Expand Down Expand Up @@ -3349,13 +3347,13 @@ spec:
are two important differences between
DataSource and DataSourceRef: * While
DataSource only allows two specific types
of objects, DataSourceRef allows any
non-core object, as well as PersistentVolumeClaim
of objects, DataSourceRef allows any non-core
object, as well as PersistentVolumeClaim
objects. * While DataSource ignores disallowed
values (dropping them), DataSourceRef preserves
all values, and generates an error if
a disallowed value is specified. (Beta)
Using this field requires the AnyVolumeDataSource
values (dropping them), DataSourceRef
preserves all values, and generates an
error if a disallowed value is specified.
(Beta) Using this field requires the AnyVolumeDataSource
feature gate to be enabled.'
properties:
apiGroup:
Expand Down Expand Up @@ -6294,13 +6292,13 @@ spec:
with a pod if it doesn''t satisfy the spread constraint.
- DoNotSchedule (default) tells the scheduler not
to schedule it. - ScheduleAnyway tells the scheduler
to schedule the pod in any location, but giving
higher precedence to topologies that would help reduce
the skew. A constraint is considered "Unsatisfiable"
for an incoming pod if and only if every possible
node assignment for that pod would violate "MaxSkew"
on some topology. For example, in a 3-zone cluster,
MaxSkew is set to 1, and pods with the same labelSelector
to schedule the pod in any location, but giving higher
precedence to topologies that would help reduce the
skew. A constraint is considered "Unsatisfiable" for
an incoming pod if and only if every possible node
assignment for that pod would violate "MaxSkew" on
some topology. For example, in a 3-zone cluster, MaxSkew
is set to 1, and pods with the same labelSelector
spread as 3/1/1: | zone1 | zone2 | zone3 | | P P P
| P | P | If WhenUnsatisfiable is set to DoNotSchedule,
incoming pod can only be scheduled to zone2(zone3)
Expand Down Expand Up @@ -6460,13 +6458,12 @@ spec:
description: "Condition contains details for one aspect of the current
state of this API Resource. --- This struct is intended for direct
use as an array at the field path .status.conditions. For example,
type FooStatus struct{ // Represents the observations of a
foo's current state. // Known .status.conditions.type are:
\"Available\", \"Progressing\", and \"Degraded\" // +patchMergeKey=type
\ // +patchStrategy=merge // +listType=map // +listMapKey=type
\ Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`
\n // other fields }"
type FooStatus struct{ // Represents the observations of a foo's
current state. // Known .status.conditions.type are: \"Available\",
\"Progressing\", and \"Degraded\" // +patchMergeKey=type // +patchStrategy=merge
// +listType=map // +listMapKey=type Conditions []metav1.Condition
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
protobuf:\"bytes,1,rep,name=conditions\"` \n // other fields }"
properties:
lastTransitionTime:
description: lastTransitionTime is the last time the condition
Expand Down Expand Up @@ -6545,9 +6542,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
9 changes: 1 addition & 8 deletions config/crd/bases/matryoshka.onmetal.de_kubeconfigs.yaml
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.7.0
controller-gen.kubebuilder.io/version: v0.9.0
creationTimestamp: null
name: kubeconfigs.matryoshka.onmetal.de
spec:
Expand Down Expand Up @@ -214,9 +213,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
61 changes: 26 additions & 35 deletions config/crd/bases/matryoshka.onmetal.de_kubecontrollermanagers.yaml
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.7.0
controller-gen.kubebuilder.io/version: v0.9.0
creationTimestamp: null
name: kubecontrollermanagers.matryoshka.onmetal.de
spec:
Expand Down Expand Up @@ -3217,13 +3216,12 @@ spec:
when the pod is removed. \n Use this if: a) the volume
is only needed while the pod runs, b) features of
normal volumes like restoring from snapshot or capacity
\ tracking are needed, c) the storage driver is
specified through a storage class, and d) the storage
driver supports dynamic volume provisioning through
\ a PersistentVolumeClaim (see EphemeralVolumeSource
for more information on the connection between
this volume type and PersistentVolumeClaim). \n
Use PersistentVolumeClaim or one of the vendor-specific
tracking are needed, c) the storage driver is specified
through a storage class, and d) the storage driver
supports dynamic volume provisioning through a PersistentVolumeClaim
(see EphemeralVolumeSource for more information on
the connection between this volume type and PersistentVolumeClaim).
\n Use PersistentVolumeClaim or one of the vendor-specific
APIs for volumes that persist for longer than the
lifecycle of an individual pod. \n Use CSI for light-weight
local ephemeral volumes if the CSI driver is meant
Expand Down Expand Up @@ -3348,13 +3346,13 @@ spec:
are two important differences between
DataSource and DataSourceRef: * While
DataSource only allows two specific types
of objects, DataSourceRef allows any
non-core object, as well as PersistentVolumeClaim
of objects, DataSourceRef allows any non-core
object, as well as PersistentVolumeClaim
objects. * While DataSource ignores disallowed
values (dropping them), DataSourceRef preserves
all values, and generates an error if
a disallowed value is specified. (Beta)
Using this field requires the AnyVolumeDataSource
values (dropping them), DataSourceRef
preserves all values, and generates an
error if a disallowed value is specified.
(Beta) Using this field requires the AnyVolumeDataSource
feature gate to be enabled.'
properties:
apiGroup:
Expand Down Expand Up @@ -6293,13 +6291,13 @@ spec:
with a pod if it doesn''t satisfy the spread constraint.
- DoNotSchedule (default) tells the scheduler not
to schedule it. - ScheduleAnyway tells the scheduler
to schedule the pod in any location, but giving
higher precedence to topologies that would help reduce
the skew. A constraint is considered "Unsatisfiable"
for an incoming pod if and only if every possible
node assignment for that pod would violate "MaxSkew"
on some topology. For example, in a 3-zone cluster,
MaxSkew is set to 1, and pods with the same labelSelector
to schedule the pod in any location, but giving higher
precedence to topologies that would help reduce the
skew. A constraint is considered "Unsatisfiable" for
an incoming pod if and only if every possible node
assignment for that pod would violate "MaxSkew" on
some topology. For example, in a 3-zone cluster, MaxSkew
is set to 1, and pods with the same labelSelector
spread as 3/1/1: | zone1 | zone2 | zone3 | | P P P
| P | P | If WhenUnsatisfiable is set to DoNotSchedule,
incoming pod can only be scheduled to zone2(zone3)
Expand Down Expand Up @@ -6439,13 +6437,12 @@ spec:
description: "Condition contains details for one aspect of the current
state of this API Resource. --- This struct is intended for direct
use as an array at the field path .status.conditions. For example,
type FooStatus struct{ // Represents the observations of a
foo's current state. // Known .status.conditions.type are:
\"Available\", \"Progressing\", and \"Degraded\" // +patchMergeKey=type
\ // +patchStrategy=merge // +listType=map // +listMapKey=type
\ Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`
\n // other fields }"
type FooStatus struct{ // Represents the observations of a foo's
current state. // Known .status.conditions.type are: \"Available\",
\"Progressing\", and \"Degraded\" // +patchMergeKey=type // +patchStrategy=merge
// +listType=map // +listMapKey=type Conditions []metav1.Condition
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
protobuf:\"bytes,1,rep,name=conditions\"` \n // other fields }"
properties:
lastTransitionTime:
description: lastTransitionTime is the last time the condition
Expand Down Expand Up @@ -6524,9 +6521,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
1 change: 0 additions & 1 deletion 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
18 changes: 9 additions & 9 deletions controllers/matryoshka/kubeapiserver_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@ package matryoshka
import (
"context"
"fmt"
"time"

. "github.com/onsi/ginkgo"
matryoshkav1alpha1 "github.com/onmetal/matryoshka/apis/matryoshka/v1alpha1"
"github.com/onmetal/matryoshka/controllers/matryoshka/internal/kubeapiserver"
"github.com/onmetal/matryoshka/controllers/matryoshka/internal/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client"

matryoshkav1alpha1 "github.com/onmetal/matryoshka/apis/matryoshka/v1alpha1"
"github.com/onmetal/matryoshka/controllers/matryoshka/internal/kubeapiserver"
"github.com/onmetal/matryoshka/controllers/matryoshka/internal/utils"
)

var _ = Describe("KubeAPIServerController", func() {
Expand All @@ -47,9 +45,11 @@ var _ = Describe("KubeAPIServerController", func() {

By("waiting for a deployment to be created")
deployment := &appsv1.Deployment{}
Eventually(func() error {
return k8sClient.Get(ctx, client.ObjectKey{Namespace: ns.Name, Name: "apiserver-sample"}, deployment)
}, 3*time.Second).Should(Succeed())
Eventually(func(g Gomega) {
err := k8sClient.Get(ctx, client.ObjectKey{Namespace: ns.Name, Name: "apiserver-sample"}, deployment)
Expect(client.IgnoreNotFound(err)).NotTo(HaveOccurred())
g.Expect(err).NotTo(HaveOccurred())
}).Should(Succeed())

By("inspecting the deployment")
Expect(deployment.Spec.Selector).To(Equal(&metav1.LabelSelector{
Expand Down
Loading

0 comments on commit f2729cc

Please sign in to comment.