Skip to content

Commit

Permalink
Add cluster wide test CRD
Browse files Browse the repository at this point in the history
  • Loading branch information
mjudeikis committed Nov 25, 2023
1 parent 64db180 commit 04fbbad
Show file tree
Hide file tree
Showing 27 changed files with 1,632 additions and 10 deletions.
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ CODE_GENERATOR_BIN := code-generator
CODE_GENERATOR := $(TOOLS_GOBIN_DIR)/$(CODE_GENERATOR_BIN)-$(CODE_GENERATOR_VER)
export CODE_GENERATOR # so hack scripts can use it

KCP_APIGEN_VER := v0.21.0
KCP_APIGEN_BIN := apigen
KCP_APIGEN_GEN := $(TOOLS_DIR)/$(KCP_APIGEN_BIN)-$(KCP_APIGEN_VER)
export KCP_APIGEN_GEN # so hack scripts can use it

ARCH := $(shell go env GOARCH)
OS := $(shell go env GOOS)

Expand Down Expand Up @@ -178,7 +183,7 @@ vendor: ## Vendor the dependencies
go mod vendor
.PHONY: vendor

tools: $(GOLANGCI_LINT) $(CONTROLLER_GEN) $(YAML_PATCH) $(GOTESTSUM) $(OPENSHIFT_GOIMPORTS) $(CODE_GENERATOR) ## Install tools
tools: $(GOLANGCI_LINT) $(CONTROLLER_GEN) $(KCP_APIGEN_GEN) $(YAML_PATCH) $(GOTESTSUM) $(OPENSHIFT_GOIMPORTS) $(CODE_GENERATOR) ## Install tools
.PHONY: tools

$(CONTROLLER_GEN):
Expand All @@ -190,6 +195,9 @@ $(YAML_PATCH):
$(GOTESTSUM):
GOBIN=$(TOOLS_GOBIN_DIR) $(GO_INSTALL) gotest.tools/gotestsum $(GOTESTSUM_BIN) $(GOTESTSUM_VER)

$(KCP_APIGEN_GEN):
GOBIN=$(TOOLS_GOBIN_DIR) $(GO_INSTALL) github.com/kcp-dev/kcp/sdk/cmd/apigen $(KCP_APIGEN_BIN) $(KCP_APIGEN_VER)

crds: $(CONTROLLER_GEN) $(YAML_PATCH) ## Generate crds
./hack/update-codegen-crds.sh
.PHONY: crds
Expand Down
17 changes: 17 additions & 0 deletions hack/update-codegen-crds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,20 @@ for CRD in "${REPO_ROOT}"/config/crds/*.yaml; do
mv "${CRD}.patched" "${CRD}"
fi
done

(
${KCP_APIGEN_GEN} --input-dir "${REPO_ROOT}"/config/crds --output-dir "${REPO_ROOT}"/config/root-phase0
)


# Tests CRDs

(
cd "${REPO_ROOT}/test/e2e/fixtures/wildwest/apis"
"${REPO_ROOT}/${CONTROLLER_GEN}" \
crd \
rbac:roleName=manager-role \
webhook \
paths="./..." \
output:crd:artifacts:config="${REPO_ROOT}"/test/e2e/fixtures/wildwest/crds
)
2 changes: 2 additions & 0 deletions test/e2e/fixtures/wildwest/apis/wildwest/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Cowboy{},
&CowboyList{},
&Sheriff{},
&SheriffList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
Expand Down
63 changes: 63 additions & 0 deletions test/e2e/fixtures/wildwest/apis/wildwest/v1alpha1/types_sheriff.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright 2021 The KCP Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// Sheriff is part of the wild west
//
// +crd
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,categories=kcp
type Sheriff struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`

// +optional
Spec SheriffSpec `json:"spec,omitempty"`

// +optional
Status SheriffStatus `json:"status,omitempty"`
}

// Sheriff holds the desired state of the Sheriff.
type SheriffSpec struct {
// +optional
Intent string `json:"intent,omitempty"`
}

// SheriffStatus communicates the observed state of the Sheriff.
type SheriffStatus struct {
// +optional
Result string `json:"result,omitempty"`
}

// SheriffList is a list of Sheriff resources
//
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type SheriffList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []Sheriff `json:"items"`
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/e2e/fixtures/wildwest/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
configcrds "github.com/kcp-dev/kcp/config/crds"
)

//go:embed *.yaml
//go:embed crds/*.yaml
var rawCustomResourceDefinitions embed.FS

func Create(t *testing.T, clustername logicalcluster.Path, client kcpapiextensionsv1client.CustomResourceDefinitionClusterInterface, grs ...metav1.GroupResource) {
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/fixtures/wildwest/client/applyconfiguration/utils.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 04fbbad

Please sign in to comment.