Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

Commit f906eb7

Browse files
authored
enhance unit testing and overall project structures (#16)
Signed-off-by: Mike Ng <[email protected]>
1 parent 6ef4eb4 commit f906eb7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1656
-251
lines changed

COMPONENT_NAME

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
multicloud-operators-channel
1+
multicluster-operators-channel

COMPONENT_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
latest
1+
2.4.0

CONTRIBUTING.md

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ contribution. See the [DCO](DCO) file for details.
2828
## Contributing A Patch
2929

3030
1. Submit an issue describing your proposed change to the repo in question.
31-
2. The [repo owners](OWNERS) will respond to your issue promptly.
32-
3. Fork the desired repo, develop and test your code changes.
33-
4. Submit a pull request.
31+
1. The [repo owners](OWNERS) will respond to your issue promptly.
32+
1. Fork the desired repo, develop and test your code changes.
33+
1. Submit a pull request.
3434

3535
## Issue and Pull Request Management
3636

@@ -45,22 +45,15 @@ Repo maintainers can assign you an issue or pull request by leaving a
4545

4646
After your PR is ready to commit, please run following commands to check your code.
4747

48-
- verify your code
49-
```shell
50-
make lint
51-
```
52-
53-
- build your code
54-
```shell
55-
make build
56-
```
57-
58-
- build a local image
59-
```shell
60-
make build-images
61-
```
62-
63-
- run the test
64-
```shell
65-
make test
66-
```
48+
```shell
49+
make build
50+
make test
51+
```
52+
53+
## Build images
54+
55+
Make sure your code build passed.
56+
57+
```shell
58+
make
59+
```

Makefile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019 The Kubernetes Authors.
1+
# Copyright 2021 The Kubernetes Authors.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -27,10 +27,9 @@ FINDFILES=find . \( -path ./.git -o -path ./.github \) -prune -o -type f
2727
XARGS = xargs -0 ${XARGS_FLAGS}
2828
CLEANXARGS = xargs ${XARGS_FLAGS}
2929

30-
IMG ?= $(shell cat COMPONENT_NAME 2> /dev/null)
3130
REGISTRY = quay.io/open-cluster-management
32-
VERSION ?= $(shell cat COMPONENT_VERSION 2> /dev/null)
33-
IMAGE_NAME_AND_VERSION ?= $(REGISTRY)/$(IMG):$(VERSION)
31+
VERSION = latest
32+
IMAGE_NAME_AND_VERSION ?= $(REGISTRY)/multicloud-operators-channel:$(VERSION)
3433
export GOPACKAGES = $(shell go list ./... | grep -v /manager | grep -v /bindata | grep -v /vendor | grep -v /internal | grep -v /build | grep -v /test | grep -v /e2e )
3534

3635
TEST_TMP :=/tmp
@@ -44,13 +43,12 @@ KB_TOOLS_ARCHIVE_PATH := $(TEST_TMP)/$(KB_TOOLS_ARCHIVE_NAME)
4443
.PHONY: build
4544

4645
build:
47-
@common/scripts/gobuild.sh build/_output/bin/$(IMG) ./cmd/manager
46+
@common/scripts/gobuild.sh build/_output/bin/multicluster-operators-channel ./cmd/manager
4847

4948
.PHONY: build-images
5049

5150
build-images: build
5251
@docker build -t ${IMAGE_NAME_AND_VERSION} -f build/Dockerfile .
53-
@docker tag ${IMAGE_NAME_AND_VERSION} $(REGISTRY)/$(IMG):latest
5452

5553
.PHONY: lint
5654

Makefile.prow

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Copyright 2021 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
-include /opt/build-harness/Makefile.prow
16+
17+
LOCAL_OS := $(shell uname)
18+
ifeq ($(LOCAL_OS),Linux)
19+
TARGET_OS ?= linux
20+
XARGS_FLAGS="-r"
21+
else ifeq ($(LOCAL_OS),Darwin)
22+
TARGET_OS ?= darwin
23+
XARGS_FLAGS=
24+
else
25+
$(error "This system's OS $(LOCAL_OS) isn't recognized/supported")
26+
endif
27+
28+
FINDFILES=find . \( -path ./.git -o -path ./.github \) -prune -o -type f
29+
XARGS = xargs -0 ${XARGS_FLAGS}
30+
CLEANXARGS = xargs ${XARGS_FLAGS}
31+
32+
IMG ?= $(shell cat COMPONENT_NAME 2> /dev/null)
33+
REGISTRY = quay.io/open-cluster-management
34+
VERSION ?= $(shell cat COMPONENT_VERSION 2> /dev/null)
35+
IMAGE_NAME_AND_VERSION ?= $(REGISTRY)/$(IMG):$(VERSION)
36+
export GOPACKAGES = $(shell go list ./... | grep -v /manager | grep -v /bindata | grep -v /vendor | grep -v /internal | grep -v /build | grep -v /test | grep -v /e2e )
37+
38+
.PHONY: build
39+
40+
build:
41+
@common/scripts/gobuild.sh build/_output/bin/$(IMG) ./cmd/manager
42+
43+
.PHONY: build-images
44+
45+
build-images: build
46+
@docker build -t ${IMAGE_NAME_AND_VERSION} -f build/Dockerfile .
47+
@docker tag ${IMAGE_NAME_AND_VERSION} $(REGISTRY)/$(IMG):latest
48+
49+
.PHONY: lint
50+
51+
lint:
52+
@build/run-code-lint.sh
53+
54+
.PHONY: lint-all
55+
56+
lint-all: lint-yaml lint-go
57+
58+
.PHONY: lint-yaml
59+
60+
lint-yaml:
61+
@${FINDFILES} \( -name '*.yml' -o -name '*.yaml' \) -print0 | ${XARGS} grep -L -e "{{" | ${CLEANXARGS} yamllint -c ./common/config/.yamllint.yml
62+
63+
.PHONY: lint-go
64+
65+
lint-go:
66+
@${FINDFILES} -name '*.go' \( ! \( -name '*.gen.go' -o -name '*.pb.go' \) \) -print0 | ${XARGS} common/scripts/lint_go.sh
67+
68+
.PHONY: test
69+
70+
test:
71+
@build/setup-tests.sh
72+
@build/run-unit-tests.sh
73+
74+
.PHONY: e2e
75+
76+
export CONTAINER_NAME=e2e
77+
e2e: build build-images
78+
build/run-e2e-tests.sh

RELEASE_MAIN_BRANCH

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
main

build/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
33
RUN microdnf update && \
44
microdnf clean all
55

6-
ENV OPERATOR=/usr/local/bin/multicloud-operators-channel \
6+
ENV OPERATOR=/usr/local/bin/multicluster-operators-channel \
77
USER_UID=1001 \
8-
USER_NAME=multicloud-operators-channel
8+
USER_NAME=multicluster-operators-channel
99

1010
# install operator binary
11-
COPY build/_output/bin/multicloud-operators-channel ${OPERATOR}
11+
COPY build/_output/bin/multicluster-operators-channel ${OPERATOR}
1212

1313
COPY build/bin /usr/local/bin
1414
RUN /usr/local/bin/user_setup

build/Dockerfile.prow

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM registry.ci.openshift.org/open-cluster-management/builder:go1.16-linux AS builder
2+
3+
WORKDIR /go/src/github.com/open-cluster-management/multicluster-operators-channel
4+
COPY . .
5+
RUN make -f Makefile.prow build
6+
7+
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
8+
9+
RUN microdnf update && \
10+
microdnf clean all
11+
12+
ENV OPERATOR=/usr/local/bin/multicluster-operators-channel \
13+
USER_UID=1001 \
14+
USER_NAME=multicluster-operators-channel
15+
16+
# install operator binary
17+
COPY --from=builder /go/src/github.com/open-cluster-management/multicluster-operators-channel/build/_output/bin/multicluster-operators-channel ${OPERATOR}
18+
19+
COPY build/bin /usr/local/bin
20+
RUN /usr/local/bin/user_setup
21+
22+
ENTRYPOINT ["/usr/local/bin/entrypoint"]
23+
24+
USER ${USER_UID}

build/build.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
#
4+
# Copyright 2021 The Kubernetes Authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
19+
echo "BUILD GOES HERE!"
20+
21+
echo "<repo>/<component>:<tag> : $1"
22+
23+
# Run our build target and set IMAGE_NAME_AND_VERSION
24+
export IMAGE_NAME_AND_VERSION=${1}
25+
make build
26+
make build-images

build/deploy-to-cluster.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2021 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
echo "DEPLOY TO CLUSTER GOES HERE! IT SHOULD DO NOTHING RIGHT NOW!"
18+
19+
exit 0;

0 commit comments

Comments
 (0)