Skip to content
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ vendor/*

!vendor/**/zz_generated.*

# envtest cached binaries
_output/

# editor and IDE paraphernalia
.idea
*.swp
Expand Down
31 changes: 7 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@

# Image URL to use all building/pushing image targets
IMG ?= quay.io/open-cluster-management/cluster-permission:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.26.0

export CGO_ENABLED=1

TEST_TMP :=/tmp
export KUBEBUILDER_ASSETS ?=$(TEST_TMP)/kubebuilder/bin
K8S_VERSION ?=1.24.1
GOHOSTOS ?=$(shell go env GOHOSTOS)
GOHOSTARCH ?= $(shell go env GOHOSTARCH)
KB_TOOLS_ARCHIVE_NAME :=kubebuilder-tools-$(K8S_VERSION)-$(GOHOSTOS)-$(GOHOSTARCH).tar.gz
KB_TOOLS_ARCHIVE_PATH := $(TEST_TMP)/$(KB_TOOLS_ARCHIVE_NAME)
ENSURE_ENVTEST_SCRIPT := https://raw.githubusercontent.com/open-cluster-management-io/sdk-go/main/ci/envtest/ensure-envtest.sh

# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
Expand Down Expand Up @@ -139,7 +131,6 @@ $(LOCALBIN):
## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest

## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
Expand All @@ -161,21 +152,13 @@ $(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

.PHONY: test

# download the kubebuilder-tools to get kube-apiserver binaries from it
ensure-kubebuilder-tools:
ifeq "" "$(wildcard $(KUBEBUILDER_ASSETS))"
$(info Downloading kube-apiserver into '$(KUBEBUILDER_ASSETS)')
mkdir -p '$(KUBEBUILDER_ASSETS)'
curl -s -f -L https://storage.googleapis.com/kubebuilder-tools/$(KB_TOOLS_ARCHIVE_NAME) -o '$(KB_TOOLS_ARCHIVE_PATH)'
tar -C '$(KUBEBUILDER_ASSETS)' --strip-components=2 -zvxf '$(KB_TOOLS_ARCHIVE_PATH)'
else
$(info Using existing kube-apiserver from "$(KUBEBUILDER_ASSETS)")
endif
.PHONY: ensure-kubebuilder-tools
.PHONY: envtest-setup
envtest-setup:
$(eval export KUBEBUILDER_ASSETS=$(shell curl -fsSL $(ENSURE_ENVTEST_SCRIPT) | bash))
@echo "KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS)"

test: ensure-kubebuilder-tools
.PHONY: test
test: envtest-setup
go test -timeout 300s -v ./controllers/... -coverprofile=coverage.out

.PHONY: deploy-ocm
Expand Down
4 changes: 2 additions & 2 deletions controllers/clusterpermission_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ var _ = Describe("ClusterPermission controller", func() {
},
}))).Should(Equal(1))

By("Create ClusterPermission with ClusterRoleBinding that has no subject or subjects")
By("Create ClusterPermission with ClusterRoleBinding that has no subject or subjects should be rejected by CRD validation")
clusterPermissionMissingSubjectSubjects := cpv1alpha1.ClusterPermission{
ObjectMeta: metav1.ObjectMeta{
Name: "clusterpermission-no-subject-subjects",
Expand All @@ -690,7 +690,7 @@ var _ = Describe("ClusterPermission controller", func() {
},
}

Expect(k8sClient.Create(ctx, &clusterPermissionMissingSubjectSubjects)).Should(Succeed())
Expect(k8sClient.Create(ctx, &clusterPermissionMissingSubjectSubjects)).ShouldNot(Succeed())

By("Create ClusterPermission with Role and ClusterRole that doesn't exist validate should have error status")
clusterPermissionRoleClusterRoleNotExistValidate := cpv1alpha1.ClusterPermission{
Expand Down