Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.

Commit 1695033

Browse files
add script dir for prow and lint and tests
Signed-off-by: Chris Hein <[email protected]>
1 parent 163817c commit 1695033

16 files changed

+275
-18
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ config/ci/manager/manager.yaml
4646
manager_image_patch.yaml-e
4747
manager_pull_policy.yaml-e
4848

49-
# Sample config files auto-generated by kubebuilder
50-
config/samples
49+
config/ci
5150

5251
# Temporary clusterctl directory
5352
cmd/clusterctl/config/manifest

.golangci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ linters:
1515
- godot
1616
- goerr113
1717
- nestif
18+
# TODO(christopherhein) Reenable these and fix errors
19+
- gosec
20+
- nakedret
21+
- unparam
22+
- staticcheck
23+
- scopelint
1824
# Run with --fast=false for more extensive checks
1925
fast: true
2026
issues:

Makefile

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ $(KUSTOMIZE): # Build kustomize from tools folder.
116116

117117
envsubst: $(ENVSUBST) ## Build a local copy of envsubst.
118118
kustomize: $(KUSTOMIZE) ## Build a local copy of kustomize.
119+
controller-gen: $(CONTROLLER_GEN) ## Build a local copy of controller-gen.
120+
golangci-lint: $(GOLANGCI_LINT) ## Build a local copy of golangci-lint.
119121

120122
## --------------------------------------
121123
## Linting
@@ -124,13 +126,9 @@ kustomize: $(KUSTOMIZE) ## Build a local copy of kustomize.
124126
.PHONY: lint lint-full
125127
lint: $(GOLANGCI_LINT) ## Lint codebase
126128
$(GOLANGCI_LINT) run -v
127-
cd $(E2E_FRAMEWORK_DIR); $(GOLANGCI_LINT) run -v
128-
cd $(CAPD_DIR); $(GOLANGCI_LINT) run -v
129129

130130
lint-full: $(GOLANGCI_LINT) ## Run slower linters to detect possible issues
131131
$(GOLANGCI_LINT) run -v --fast=false
132-
cd $(E2E_FRAMEWORK_DIR); $(GOLANGCI_LINT) run -v --fast=false
133-
cd $(CAPD_DIR); $(GOLANGCI_LINT) run -v --fast=false
134132

135133
apidiff: $(GO_APIDIFF) ## Check for API differences
136134
$(GO_APIDIFF) $(shell git rev-parse origin/master) --print-compatible
@@ -140,20 +138,19 @@ apidiff: $(GO_APIDIFF) ## Check for API differences
140138
## --------------------------------------
141139

142140
.PHONY: generate
143-
generate: ## Generate code
144-
$(MAKE) generate-manifests
141+
generate:
145142
$(MAKE) generate-go
146-
# $(MAKE) generate-bindata
143+
$(MAKE) generate-manifests
147144

148145
.PHONY: generate-go
149-
generate-go: ## Runs Go related generate targets
146+
generate-go: $(CONTROLLER_GEN) ## Runs Go related generate targets
150147
go generate ./...
151148
$(CONTROLLER_GEN) \
152149
object:headerFile=./hack/boilerplate/boilerplate.generatego.txt \
153150
paths=./apis/...
154151

155152
.PHONY: generate-manifests
156-
generate-manifests: ## Generate manifests e.g. CRD, RBAC etc.
153+
generate-manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc.
157154
$(CONTROLLER_GEN) \
158155
paths=./apis/... \
159156
paths=./controllers/... \
@@ -163,8 +160,8 @@ generate-manifests: ## Generate manifests e.g. CRD, RBAC etc.
163160
output:webhook:dir=./config/webhook \
164161
webhook
165162
## Copy files in CI folders.
166-
# cp -f ./config/rbac/*.yaml ./config/ci/rbac/
167-
# cp -f ./config/manager/manager*.yaml ./config/ci/manager/
163+
cp -f ./config/rbac/*.yaml ./config/ci/rbac/
164+
cp -f ./config/manager/manager*.yaml ./config/ci/manager/
168165

169166
.PHONY: modules
170167
modules: ## Runs go mod to ensure modules are up to date.

apis/controlplane/v1alpha4/nestedcomponent_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type NestedComponentSpec struct {
2828
// +optional
2929
addonv1alpha1.CommonSpec `json:",inline"`
3030

31-
// PatchSpecs includes the user specifed settings
31+
// PatchSpecs includes the user specified settings
3232
// +optional
3333
addonv1alpha1.PatchSpec `json:",inline"`
3434

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: controlplane.cluster.x-k8s.io/v1alpha4
2+
kind: NestedAPIServer
3+
metadata:
4+
name: nestedapiserver-sample
5+
spec:
6+
replicas: 1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: controlplane.cluster.x-k8s.io/v1alpha4
2+
kind: NestedControllerManager
3+
metadata:
4+
name: nestedcontrollermanager-sample
5+
spec:
6+
replicas: 1
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: controlplane.cluster.x-k8s.io/v1alpha4
2+
kind: NestedControlPlane
3+
metadata:
4+
name: nestedcontrolplane-sample
5+
spec:
6+
etcd:
7+
apiVersion: controlplane.cluster.x-k8s.io/v1alpha4
8+
kind: NestedEtcd
9+
name: nestedetcd-sample
10+
apiserver:
11+
apiVersion: controlplane.cluster.x-k8s.io/v1alpha4
12+
kind: NestedAPIServer
13+
name: nestedapiserver-sample
14+
controllerManager:
15+
apiVersion: controlplane.cluster.x-k8s.io/v1alpha4
16+
kind: NestedControllerManager
17+
name: nestedcontrollermanager-sample
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: controlplane.cluster.x-k8s.io/v1alpha4
2+
kind: NestedEtcd
3+
metadata:
4+
name: nestedetcd-sample
5+
spec:
6+
replicas: 1
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha4
2+
kind: NestedCluster
3+
metadata:
4+
name: nestedcluster-sample
5+
spec:
6+
controlPlaneEndpoint:
7+
host: "localhost"
8+
port: 6443

config/samples/v1alpha4_cluster.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: cluster.x-k8s.io/v1alpha4
2+
kind: Cluster
3+
metadata:
4+
name: cluster-sample
5+
namespace: default
6+
spec:
7+
controlPlaneEndpoint:
8+
# currently this has to be the in-cluster endpoint, the in-cluster
9+
# kubeconfig is used by controller-manager w/ ClusterIP services
10+
# we can `port-forward` this service and be able to test
11+
host: "cluster-sample-apiserver"
12+
port: 6443
13+
controlPlaneRef:
14+
apiVersion: controlplane.cluster.x-k8s.io/v1alpha4
15+
kind: NestedControlPlane
16+
name: nestedcontrolplane-sample
17+
namespace: default
18+
infrastructureRef:
19+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha4
20+
kind: NestedCluster
21+
name: nestedcluster-sample
22+
namespace: default

controllers/controlplane/controller_util_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func TestGetOwner(t *testing.T) {
153153
t.Parallel()
154154
t.Logf("\tTestCase: %s", st.name)
155155
{
156-
get := getOwner(st.netcd)
156+
get := getOwner(st.netcd.ObjectMeta)
157157
if !reflect.DeepEqual(get, st.expect) {
158158
t.Fatalf("\t%s\texpect %v, but get %v", failed, st.expect, get)
159159
}

controllers/controlplane/nestedetcd_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func getNestedEtcdSvcClusterIP(ctx context.Context, cli ctrlcli.Client,
187187
return svc.Spec.ClusterIP, nil
188188
}
189189

190-
// genInitialClusterArgs generates the values for `--inital-cluster` option of
190+
// genInitialClusterArgs generates the values for `--initial-cluster` option of
191191
// etcd based on the number of replicas specified in etcd StatefulSet
192192
func genInitialClusterArgs(replicas int32,
193193
stsName, svcName string) (argsVal string) {
@@ -196,10 +196,10 @@ func genInitialClusterArgs(replicas int32,
196196
peerAddr := fmt.Sprintf("%s-%d=https://%s-%d.%s:%d",
197197
stsName, i, stsName, i, svcName, 2380)
198198
if i == replicas-1 {
199-
argsVal = argsVal + peerAddr
199+
argsVal += peerAddr
200200
break
201201
}
202-
argsVal = argsVal + peerAddr + ","
202+
argsVal += peerAddr + ","
203203
}
204204

205205
return argsVal

scripts/ci-build.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
22+
# shellcheck source=../hack/ensure-go.sh
23+
source "${REPO_ROOT}/hack/ensure-go.sh"
24+
25+
cd "${REPO_ROOT}" && make binaries

scripts/ci-make.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
22+
# shellcheck source=../hack/ensure-go.sh
23+
source "${REPO_ROOT}/hack/ensure-go.sh"
24+
25+
cd "${REPO_ROOT}" && make docker-build

scripts/ci-test.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
22+
# shellcheck source=../hack/ensure-go.sh
23+
source "${REPO_ROOT}/hack/ensure-go.sh"
24+
25+
cd "${REPO_ROOT}" && \
26+
source ./scripts/fetch_ext_bins.sh && \
27+
fetch_tools && \
28+
setup_envs && \
29+
make generate lint test

scripts/fetch_ext_bins.sh

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2021 The Kubernetes Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -o errexit
17+
set -o nounset
18+
set -o pipefail
19+
20+
# Enable tracing in this script off by setting the TRACE variable in your
21+
# environment to any value:
22+
#
23+
# $ TRACE=1 test.sh
24+
TRACE=${TRACE:-""}
25+
if [[ -n "${TRACE}" ]]; then
26+
set -x
27+
fi
28+
29+
k8s_version=1.16.4
30+
goarch=amd64
31+
goos="unknown"
32+
33+
if [[ "${OSTYPE}" == "linux"* ]]; then
34+
goos="linux"
35+
elif [[ "${OSTYPE}" == "darwin"* ]]; then
36+
goos="darwin"
37+
fi
38+
39+
if [[ "$goos" == "unknown" ]]; then
40+
echo "OS '$OSTYPE' not supported. Aborting." >&2
41+
exit 1
42+
fi
43+
44+
# Turn colors in this script off by setting the NO_COLOR variable in your
45+
# environment to any value:
46+
#
47+
# $ NO_COLOR=1 test.sh
48+
NO_COLOR=${NO_COLOR:-""}
49+
if [[ -z "${NO_COLOR}" ]]; then
50+
header=$'\e[1;33m'
51+
reset=$'\e[0m'
52+
else
53+
header=''
54+
reset=''
55+
fi
56+
57+
function header_text {
58+
echo "$header$*$reset"
59+
}
60+
61+
tmp_root=/tmp
62+
63+
kb_root_dir=${tmp_root}/kubebuilder
64+
65+
# Skip fetching and untaring the tools by setting the SKIP_FETCH_TOOLS variable
66+
# in your environment to any value:
67+
#
68+
# $ SKIP_FETCH_TOOLS=1 ./fetch_ext_bins.sh
69+
#
70+
# If you skip fetching tools, this script will use the tools already on your
71+
# machine, but rebuild the kubebuilder and kubebuilder-bin binaries.
72+
SKIP_FETCH_TOOLS=${SKIP_FETCH_TOOLS:-""}
73+
74+
function prepare_staging_dir {
75+
header_text "preparing staging dir"
76+
77+
if [[ -z "${SKIP_FETCH_TOOLS}" ]]; then
78+
rm -rf "${kb_root_dir}"
79+
else
80+
rm -f "${kb_root_dir}/kubebuilder/bin/kubebuilder"
81+
rm -f "${kb_root_dir}/kubebuilder/bin/kubebuilder-gen"
82+
rm -f "${kb_root_dir}/kubebuilder/bin/vendor.tar.gz"
83+
fi
84+
}
85+
86+
# fetch k8s API gen tools and make it available under kb_root_dir/bin.
87+
function fetch_tools {
88+
if [[ -n "$SKIP_FETCH_TOOLS" ]]; then
89+
return 0
90+
fi
91+
92+
header_text "fetching tools"
93+
kb_tools_archive_name="kubebuilder-tools-${k8s_version}-${goos}-${goarch}.tar.gz"
94+
kb_tools_download_url="https://storage.googleapis.com/kubebuilder-tools/${kb_tools_archive_name}"
95+
96+
kb_tools_archive_path="${tmp_root}/${kb_tools_archive_name}"
97+
if [[ ! -f ${kb_tools_archive_path} ]]; then
98+
curl -fsL ${kb_tools_download_url} -o "${kb_tools_archive_path}"
99+
fi
100+
tar -zvxf "${kb_tools_archive_path}" -C "${tmp_root}/"
101+
}
102+
103+
function setup_envs {
104+
header_text "setting up env vars"
105+
106+
# Setup env vars
107+
export PATH=/tmp/kubebuilder/bin:$PATH
108+
export TEST_ASSET_KUBECTL=/tmp/kubebuilder/bin/kubectl
109+
export TEST_ASSET_KUBE_APISERVER=/tmp/kubebuilder/bin/kube-apiserver
110+
export TEST_ASSET_ETCD=/tmp/kubebuilder/bin/etcd
111+
}

0 commit comments

Comments
 (0)