From 3e937b7904af0c08d7bb6151f792d1d7f6080698 Mon Sep 17 00:00:00 2001 From: Pawan Pinjarkar Date: Wed, 26 Feb 2025 10:11:33 -0500 Subject: [PATCH] Initial changes --- Makefile | 37 +++++++++++++++++-- config/crd/bases/ofcir.openshift_cipools.yaml | 19 ++++++---- .../bases/ofcir.openshift_ciresources.yaml | 29 +++++++++------ config/rbac/role.yaml | 28 +------------- pkg/server/server.go | 1 - tests/e2e/main_test.go | 4 +- 6 files changed, 68 insertions(+), 50 deletions(-) diff --git a/Makefile b/Makefile index 5a385e7..3285ec5 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,12 @@ # Image URL to use all building/pushing image targets -IMG ?= localhost/ofcir:latest +IMG ?= localhost/ofcir-test:latest # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. ENVTEST_K8S_VERSION = 1.23 # KUSTOMIZE_BUILD_DIR defines the root folder to be used for manifests generation KUSTOMIZE_BUILD_DIR ?= config/default +CONTAINER_NAME=e2e-test +LOG_FILE=e2e-test.log # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) @@ -81,13 +83,36 @@ unit-tests: fmt vet e2e-tests: go test ./tests/e2e/... +e2e-tests-container: delete-cluster cleantmp create-cluster ofcir-image export-ofcir-image load-ofcir-image + + docker run --name e2e-test --rm \ + --network host \ + -v $(PWD):/app \ + -v $(HOME)/.kube:/root/.kube \ + -e KUBECONFIG=/root/.kube/config \ + -e KUBERNETES_SERVICE_HOST=127.0.0.1 \ + -e KUBERNETES_SERVICE_PORT=6443 \ + -w /app golang:1.23 bash -c "apt-get update && apt-get install -y make git docker.io libvirt-dev pkg-config curl && curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.23.0/bin/linux/amd64/kubectl && chmod +x kubectl && mv kubectl /usr/local/bin/ && go install sigs.k8s.io/controller-tools/cmd/controller-ge@$(CONTROLLER_TOOLS_VERSION) && go mod tidy && make e2e-tests" + +cleantmp: + rm -rf /tmp/ofcir-latest.tar + +export-ofcir-image: + podman save -o /tmp/ofcir-latest.tar localhost/ofcir-test:latest + +copy-e2e-logs: + podman cp $(CONTAINER_NAME):/app/$(LOG_FILE) ./$(LOG_FILE) + +load-ofcir-image: + /usr/local/bin/kind load image-archive --name ofcir-test /tmp/ofcir-latest.tar + .PHONY: run run: manifests generate fmt vet ## Run a controller from your host. go run ./main.go .PHONY: ofcir-image ofcir-image: - podman build -t ${IMG} -f Dockerfile . + docker build -t ${IMG} -f Dockerfile . ##@ Deployment @@ -162,4 +187,10 @@ $(ENVTEST): $(LOCALBIN) GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest .PHONY: runapi -runapi: manifests generate fmt vet ## Run a controller from your host. \ No newline at end of file +runapi: manifests generate fmt vet ## Run a controller from your host. + +create-cluster: + /usr/local/bin/kind create cluster --name ofcir-test --image kindest/node:v1.30.0 --config tests/e2e/kind-config.yaml + +delete-cluster: + /usr/local/bin/kind delete cluster --name ofcir-test \ No newline at end of file diff --git a/config/crd/bases/ofcir.openshift_cipools.yaml b/config/crd/bases/ofcir.openshift_cipools.yaml index 86eafba..3c49e89 100644 --- a/config/crd/bases/ofcir.openshift_cipools.yaml +++ b/config/crd/bases/ofcir.openshift_cipools.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.12.0 + controller-gen.kubebuilder.io/version: v0.17.0 name: cipools.ofcir.openshift spec: group: ofcir.openshift @@ -47,14 +47,19 @@ spec: description: CIPool is the Schema for the cipools API properties: apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources type: string kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds type: string metadata: type: object diff --git a/config/crd/bases/ofcir.openshift_ciresources.yaml b/config/crd/bases/ofcir.openshift_ciresources.yaml index de840f0..da8695d 100644 --- a/config/crd/bases/ofcir.openshift_ciresources.yaml +++ b/config/crd/bases/ofcir.openshift_ciresources.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.12.0 + controller-gen.kubebuilder.io/version: v0.17.0 name: ciresources.ofcir.openshift spec: group: ofcir.openshift @@ -48,14 +48,19 @@ spec: instances) from a specific pool properties: apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources type: string kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds type: string metadata: type: object @@ -70,8 +75,9 @@ spec: CIResource properties: name: - description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - TODO: Add other useful fields. apiVersion, kind, uid?' + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names type: string type: object x-kubernetes-map-type: atomic @@ -94,8 +100,9 @@ spec: description: Public IPv4 address type: string extra: - description: This field may contain extra data that may vary depending - on the specific resource type used + description: |- + This field may contain extra data that may vary depending on the + specific resource type used type: string lastUpdated: description: LastUpdated identifies when this status was last observed. diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 78f4e5c..c6baf47 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -21,32 +21,6 @@ rules: - ofcir.openshift resources: - cipools - verbs: - - create - - delete - - deletecollection - - get - - list - - patch - - update - - watch -- apiGroups: - - ofcir.openshift - resources: - - cipools/finalizers - verbs: - - update -- apiGroups: - - ofcir.openshift - resources: - - cipools/status - verbs: - - get - - patch - - update -- apiGroups: - - ofcir.openshift - resources: - ciresources verbs: - create @@ -60,12 +34,14 @@ rules: - apiGroups: - ofcir.openshift resources: + - cipools/finalizers - ciresources/finalizers verbs: - update - apiGroups: - ofcir.openshift resources: + - cipools/status - ciresources/status verbs: - get diff --git a/pkg/server/server.go b/pkg/server/server.go index cab3a02..7e1190d 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -43,7 +43,6 @@ func (o *OfcirAPI) Init(kubeconfig string) error { var err error var config *rest.Config - // Use this option when running outside the cluster if kubeconfig != "" { config, err = clientcmd.BuildConfigFromFlags("", kubeconfig) } else { diff --git a/tests/e2e/main_test.go b/tests/e2e/main_test.go index ad03194..49a754c 100644 --- a/tests/e2e/main_test.go +++ b/tests/e2e/main_test.go @@ -43,8 +43,8 @@ func TestMain(m *testing.M) { testenv = env.New() testenv.Setup( - createKindCluster(kindClusterName), - buildAndLoadOfcirImage, + // createKindCluster(kindClusterName), + // buildAndLoadOfcirImage, deployOfcirOperator, )