Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 1 addition & 9 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
test:
name: "Unit test"
runs-on: ubuntu-latest
timeout-minutes: 5
timeout-minutes: 10

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, did you notice an increase in timeouts?

@sozercan sozercan Jan 19, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i added -race -bench to align with GK which increased the timeouts (mostly due to benchmarks)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason we added is to make sure to run benchmarks often so we don't break them

steps:
- name: Set up Go 1.19
uses: actions/setup-go@v3
Expand All @@ -34,14 +34,6 @@ jobs:
with:
path: go/src/github.com/open-policy-agent/frameworks

- name: Install tools
run: |
curl -L -O "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${KUBEBUILDER_VERSION}/kubebuilder_${KUBEBUILDER_VERSION}_linux_amd64.tar.gz" &&\
tar -zxvf kubebuilder_${KUBEBUILDER_VERSION}_linux_amd64.tar.gz &&\
sudo mv kubebuilder_${KUBEBUILDER_VERSION}_linux_amd64 /usr/local/kubebuilder
env:
KUBEBUILDER_VERSION: 2.3.1

- name: Unit test
run: |
export PATH=$PATH:${GOBIN}
Expand Down
36 changes: 11 additions & 25 deletions constraint/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
# Build the manager binary
FROM golang:1.19 as builder
FROM golang:1.19-bullseye as builder

RUN apt-get update &&\
apt-get install -y apt-utils make
ARG KUSTOMIZE_VERSION

# Install kubebuilder
WORKDIR /scratch
ENV version=2.3.2
ENV arch=amd64
RUN curl -L -O "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${version}/kubebuilder_${version}_linux_${arch}.tar.gz" &&\
tar -zxvf kubebuilder_${version}_linux_${arch}.tar.gz &&\
mv kubebuilder_${version}_linux_${arch} /usr/local/kubebuilder &&\
rm kubebuilder_${version}_linux_${arch}.tar.gz
ENV PATH=$PATH:/usr/local/kubebuilder/bin:/usr/bin
ARG TARGETARCH

# Install kustomize
ENV version=3.8.9
ENV arch=amd64
ENV tar_name=kustomize_v${version}_linux_${arch}.tar.gz
RUN curl -LO "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv${version}/${tar_name}" &&\
tar -xf ${tar_name} &&\
mv ./kustomize /usr/bin/kustomize &&\
chmod u+x /usr/bin/kustomize
RUN apt-get update && \
apt-get install -y make

# Copy in the go src
WORKDIR /go/src/github.com/open-policy-agent/frameworks/constraint
COPY . .
# Install kustomize
RUN curl -L -O "https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv${KUSTOMIZE_VERSION}/kustomize_v${KUSTOMIZE_VERSION}_linux_${TARGETARCH}.tar.gz" &&\
tar -zxvf kustomize_v${KUSTOMIZE_VERSION}_linux_${TARGETARCH}.tar.gz &&\
chmod +x kustomize &&\
mv kustomize /usr/local/bin

ENTRYPOINT ["make", "docker-internal-test"]
WORKDIR /app
43 changes: 30 additions & 13 deletions constraint/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# When updating this, make sure to update the corresponding action in
# workflow.yaml
GOLANGCI_LINT_VERSION := v1.45.2
GOLANGCI_LINT_VERSION ?= 1.50.0
KUSTOMIZE_VERSION ?= 3.8.9
KUBERNETES_VERSION ?= 1.26.0

# Detects the location of the user golangci-lint cache.
GOLANGCI_LINT_CACHE := $(shell pwd)/.tmp/golangci-lint
Expand All @@ -18,19 +20,15 @@ all: lint test

# Run tests
# TODO: Once https://github.com/kubernetes/kubernetes/issues/101567 is fixed, add `generate` back as a dependency target
native-test: gen-dependencies manifests
go test ./pkg/... -coverprofile cover.out

# Docker internal test
docker-internal-test:
make native-test
# The remote driver has some unimplemented functions
# which result in a panic during testing.
# ./tests/test_remote_driver.sh
native-test: gen-dependencies manifests envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(KUBERNETES_VERSION) --bin-dir $(LOCALBIN) -p path)" \
GO111MODULE=on \
go test -mod vendor ./pkg/... -race -bench . -coverprofile cover.out

# Hook to run docker tests
test:
docker build . -t constraint-test && docker run constraint-test
.PHONY: test
test: __test-image
docker run --rm -v $(shell pwd):/app constraint-test make native-test

# Install CRDs into a cluster
install: manifests
Expand Down Expand Up @@ -60,7 +58,7 @@ manifests:
lint:
docker run --rm -v $(shell pwd):/app \
-v ${GOLANGCI_LINT_CACHE}:/root/.cache/golangci-lint \
-w /app golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine \
-w /app golangci/golangci-lint:v${GOLANGCI_LINT_VERSION}-alpine \
golangci-lint run -v

# Generate code
Expand Down Expand Up @@ -109,3 +107,22 @@ generate-defaults: constraint-template-string-constant
vendor:
go mod vendor
go mod tidy

.PHONY: __test-image
__test-image:
docker buildx build . \
-t constraint-test \
--load \
--build-arg KUSTOMIZE_VERSION=$(KUSTOMIZE_VERSION)

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user runs this in their source code directory, this will create a /bin folder. Do we want to put this in an easy-to-clean subdir (.output or similar)? Is the /bin directory part of .gitignore?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like bin would be ignored, though I'd personally consider putting this in a .output directory to make it easy to wipe everything and start from zero.

@sozercan sozercan Jan 20, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxsmythe bin is the default for kubebuilder v3 and it's in gitignore. looks like we are using .tmp already (for linter) so i changed to .tmp/bin

$(LOCALBIN):
mkdir -p $(LOCALBIN)

ENVTEST ?= $(LOCALBIN)/setup-envtest

.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@v0.0.0-20230118154835-9241bceb3098