Skip to content

Commit d2ce01e

Browse files
dhaiducekopenshift-merge-robot
authored andcommitted
Upgrade: Go v1.20 and packages
ref: https://issues.redhat.com/browse/ACM-5042 Signed-off-by: Dale Haiducek <[email protected]>
1 parent ed65625 commit d2ce01e

26 files changed

+450
-1320
lines changed

Makefile

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ clean:
107107

108108
.PHONY: fmt-dependencies
109109
fmt-dependencies:
110-
$(call go-get-tool,github.com/daixiang0/gci@v0.2.9)
111-
$(call go-get-tool,mvdan.cc/gofumpt@v0.2.0)
110+
$(call go-get-tool,github.com/daixiang0/gci@v0.10.1)
111+
$(call go-get-tool,mvdan.cc/gofumpt@v0.5.0)
112112

113113
# All available format: format-go format-protos format-python
114114
# Default value will run all formats, override these make target with your requirements:
@@ -117,7 +117,7 @@ fmt-dependencies:
117117
fmt: fmt-dependencies
118118
find . -not \( -path "./.go" -prune \) -name "*.go" | xargs gofmt -s -w
119119
find . -not \( -path "./.go" -prune \) -name "*.go" | xargs gofumpt -l -w
120-
find . -not \( -path "./.go" -prune \) -name "*.go" | xargs gci -w -local "$(shell cat go.mod | head -1 | cut -d " " -f 2)"
120+
find . -not \( -path "./.go" -prune \) -name "*.go" | xargs gci write -s standard -s default -s "prefix($(shell cat go.mod | head -1 | cut -d " " -f 2))"
121121

122122
############################################################
123123
# check section
@@ -128,7 +128,7 @@ check: lint
128128

129129
.PHONY: lint-dependencies
130130
lint-dependencies:
131-
$(call go-get-tool,github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2)
131+
$(call go-get-tool,github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2)
132132

133133
# All available linters: lint-dockerfiles lint-scripts lint-yaml lint-copyright-banner lint-go lint-python lint-helm lint-markdown lint-sass lint-typescript lint-protos
134134
# Default value will run all linters, override these make target with your requirements:
@@ -141,19 +141,20 @@ lint: lint-dependencies lint-all
141141
############################################################
142142
GOSEC = $(LOCAL_BIN)/gosec
143143
KUBEBUILDER = $(LOCAL_BIN)/kubebuilder
144-
KBVERSION = 3.2.0
145-
K8S_VERSION = 1.21.2
144+
ENVTEST = $(LOCAL_BIN)/setup-envtest
145+
KBVERSION = 3.12.0
146+
ENVTEST_K8S_VERSION = 1.26.x
146147

147148
.PHONY: test
148149
test: test-dependencies
149-
KUBEBUILDER_ASSETS=$(LOCAL_BIN) go test $(TESTARGS) `go list ./... | grep -v test/e2e`
150+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test $(TESTARGS) `go list ./... | grep -v test/e2e`
150151

151152
.PHONY: test-coverage
152153
test-coverage: TESTARGS = -json -cover -covermode=atomic -coverprofile=coverage_unit.out
153154
test-coverage: test
154155

155156
.PHONY: test-dependencies
156-
test-dependencies: kubebuilder-dependencies kubebuilder
157+
test-dependencies: envtest kubebuilder
157158

158159
.PHONY: kubebuilder
159160
kubebuilder:
@@ -163,17 +164,13 @@ kubebuilder:
163164
chmod +x $(KUBEBUILDER); \
164165
fi
165166

166-
.PHONY: kubebuilder-dependencies
167-
kubebuilder-dependencies: $(LOCAL_BIN)
168-
@if [ ! -f $(LOCAL_BIN)/etcd ] || [ ! -f $(LOCAL_BIN)/kube-apiserver ] || [ ! -f $(LOCAL_BIN)/kubectl ] || \
169-
[ "$$($(KUBEBUILDER) version 2>/dev/null | grep -o KubeBuilderVersion:\"[0-9]*\.[0-9]\.[0-9]*\")" != "KubeBuilderVersion:\"$(KBVERSION)\"" ]; then \
170-
echo "Installing envtest Kubebuilder assets"; \
171-
curl -L "https://go.kubebuilder.io/test-tools/$(K8S_VERSION)/$(GOOS)/$(GOARCH)" | tar xz --strip-components=2 -C $(LOCAL_BIN); \
172-
fi
167+
.PHONY: envtest
168+
envtest:
169+
$(call go-get-tool,sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
173170

174171
.PHONY: gosec
175172
gosec:
176-
$(call go-get-tool,github.com/securego/gosec/v2/cmd/gosec@v2.9.6)
173+
$(call go-get-tool,github.com/securego/gosec/v2/cmd/gosec@v2.15.0)
177174

178175
.PHONY: gosec-scan
179176
gosec-scan: gosec
@@ -228,7 +225,7 @@ controller-gen: ## Download controller-gen locally if necessary.
228225

229226
.PHONY: kustomize
230227
kustomize: ## Download kustomize locally if necessary.
231-
$(call go-get-tool,sigs.k8s.io/kustomize/kustomize/[email protected])
228+
$(call go-get-tool,sigs.k8s.io/kustomize/kustomize/[email protected])
232229

233230
############################################################
234231
# e2e test section

build/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Stage 1: Use image builder to build the target binaries
22
# Copyright Contributors to the Open Cluster Management project
33

4-
FROM golang:1.19 AS builder
4+
FROM golang:1.20 AS builder
55

66
ENV COMPONENT=governance-policy-framework-addon
77
ENV REPO_PATH=/go/src/github.com/open-cluster-management-io/${COMPONENT}

build/common/config/.golangci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
service:
2-
# When updating this, also update the version stored in docker/build-tools/Dockerfile in the multicloudlab/tools repo.
3-
golangci-lint-version: 1.41.x # use the fixed version to not introduce new linters unexpectedly
41
run:
52
# timeout for analysis, e.g. 30s, 5m, default is 1m
63
deadline: 20m
7-
go: '1.17'
84
timeout: 20m
95

106
# which dirs to skip: they won't be analyzed;

controllers/gatekeepersync/gatekeeper_constraint_sync.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package gatekeepersync
44

55
import (
66
"context"
7-
87
// #nosec G505
98
"crypto/sha1"
109
"encoding/json"

controllers/secretsync/secret_sync_test.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func getTestSecret() *corev1.Secret {
2828
// Generate an AES-256 key and stored it as a Secret on the Hub.
2929
key := make([]byte, keySize/8)
3030
_, err := rand.Read(key)
31-
Expect(err).To(BeNil())
31+
Expect(err).ToNot(HaveOccurred())
3232

3333
return &corev1.Secret{
3434
ObjectMeta: metav1.ObjectMeta{
@@ -41,7 +41,7 @@ func getTestSecret() *corev1.Secret {
4141
}
4242
}
4343

44-
func TestReconcileSecretHubOnly(t *testing.T) {
44+
func TestReconcileSecretHubOnly(_ *testing.T) {
4545
RegisterFailHandler(Fail)
4646

4747
encryptionSecret := getTestSecret()
@@ -55,16 +55,16 @@ func TestReconcileSecretHubOnly(t *testing.T) {
5555
NamespacedName: types.NamespacedName{Name: SecretName, Namespace: clusterName},
5656
}
5757
_, err := r.Reconcile(context.TODO(), request)
58-
Expect(err).To(BeNil())
58+
Expect(err).ToNot(HaveOccurred())
5959

6060
// Verify that the Secret was synced to the managed cluster by the Reconciler.
6161
managedEncryptionSecret := &corev1.Secret{}
6262
err = managedClient.Get(context.TODO(), request.NamespacedName, managedEncryptionSecret)
63-
Expect(err).To(BeNil())
64-
Expect(len(managedEncryptionSecret.Data["key"])).To(Equal(keySize / 8))
63+
Expect(err).ToNot(HaveOccurred())
64+
Expect(managedEncryptionSecret.Data["key"]).To(HaveLen(keySize / 8))
6565
}
6666

67-
func TestReconcileSecretHubOnlyDiffTargetNS(t *testing.T) {
67+
func TestReconcileSecretHubOnlyDiffTargetNS(_ *testing.T) {
6868
RegisterFailHandler(Fail)
6969

7070
encryptionSecret := getTestSecret()
@@ -79,18 +79,18 @@ func TestReconcileSecretHubOnlyDiffTargetNS(t *testing.T) {
7979
NamespacedName: types.NamespacedName{Name: SecretName, Namespace: clusterName},
8080
}
8181
_, err := r.Reconcile(context.TODO(), request)
82-
Expect(err).To(BeNil())
82+
Expect(err).ToNot(HaveOccurred())
8383

8484
// Verify that the Secret was synced to the managed cluster by the Reconciler.
8585
managedEncryptionSecret := &corev1.Secret{}
8686
err = managedClient.Get(
8787
context.TODO(), types.NamespacedName{Name: SecretName, Namespace: "other-ns"}, managedEncryptionSecret,
8888
)
89-
Expect(err).To(BeNil())
90-
Expect(len(managedEncryptionSecret.Data["key"])).To(Equal(keySize / 8))
89+
Expect(err).ToNot(HaveOccurred())
90+
Expect(managedEncryptionSecret.Data["key"]).To(HaveLen(keySize / 8))
9191
}
9292

93-
func TestReconcileSecretAlreadySynced(t *testing.T) {
93+
func TestReconcileSecretAlreadySynced(_ *testing.T) {
9494
RegisterFailHandler(Fail)
9595

9696
encryptionSecret := getTestSecret()
@@ -102,24 +102,24 @@ func TestReconcileSecretAlreadySynced(t *testing.T) {
102102
NamespacedName: types.NamespacedName{Name: SecretName, Namespace: clusterName},
103103
}
104104
err := managedClient.Get(context.TODO(), request.NamespacedName, managedEncryptionSecret)
105-
Expect(err).To(BeNil())
105+
Expect(err).ToNot(HaveOccurred())
106106

107107
version := managedEncryptionSecret.ObjectMeta.ResourceVersion
108108

109109
r := SecretReconciler{
110110
Client: hubClient, ManagedClient: managedClient, Scheme: scheme.Scheme, TargetNamespace: clusterName,
111111
}
112112
_, err = r.Reconcile(context.TODO(), request)
113-
Expect(err).To(BeNil())
113+
Expect(err).ToNot(HaveOccurred())
114114

115115
// Verify that the Secret was not modified by the Reconciler.
116116
managedEncryptionSecret = &corev1.Secret{}
117117
err = managedClient.Get(context.TODO(), request.NamespacedName, managedEncryptionSecret)
118-
Expect(err).To(BeNil())
118+
Expect(err).ToNot(HaveOccurred())
119119
Expect(managedEncryptionSecret.ResourceVersion).To(Equal(version))
120120
}
121121

122-
func TestReconcileSecretMismatch(t *testing.T) {
122+
func TestReconcileSecretMismatch(_ *testing.T) {
123123
RegisterFailHandler(Fail)
124124

125125
hubEncryptionSecret := getTestSecret()
@@ -135,16 +135,16 @@ func TestReconcileSecretMismatch(t *testing.T) {
135135
Client: hubClient, ManagedClient: managedClient, Scheme: scheme.Scheme, TargetNamespace: clusterName,
136136
}
137137
_, err := r.Reconcile(context.TODO(), request)
138-
Expect(err).To(BeNil())
138+
Expect(err).ToNot(HaveOccurred())
139139

140140
// Verify that the Secret was updated by the Reconciler.
141141
managedEncryptionSecret = &corev1.Secret{}
142142
err = managedClient.Get(context.TODO(), request.NamespacedName, managedEncryptionSecret)
143-
Expect(err).To(BeNil())
144-
Expect(len(managedEncryptionSecret.Data["key"])).To(Equal(keySize / 8))
143+
Expect(err).ToNot(HaveOccurred())
144+
Expect(managedEncryptionSecret.Data["key"]).To(HaveLen(keySize / 8))
145145
}
146146

147-
func TestReconcileSecretDeletedOnHub(t *testing.T) {
147+
func TestReconcileSecretDeletedOnHub(_ *testing.T) {
148148
RegisterFailHandler(Fail)
149149

150150
encryptionSecret := getTestSecret()
@@ -158,7 +158,7 @@ func TestReconcileSecretDeletedOnHub(t *testing.T) {
158158
NamespacedName: types.NamespacedName{Name: SecretName, Namespace: clusterName},
159159
}
160160
_, err := r.Reconcile(context.TODO(), request)
161-
Expect(err).To(BeNil())
161+
Expect(err).ToNot(HaveOccurred())
162162

163163
// Verify that the Secret was deleted on the managed cluster by the Reconciler.
164164
managedEncryptionSecret := &corev1.Secret{}
@@ -168,7 +168,7 @@ func TestReconcileSecretDeletedOnHub(t *testing.T) {
168168

169169
// The tested code should occur in production because of the field selector set on the watch, but
170170
// the code should still account for it.
171-
func TestReconcileInvalidSecretName(t *testing.T) {
171+
func TestReconcileInvalidSecretName(_ *testing.T) {
172172
RegisterFailHandler(Fail)
173173

174174
encryptionSecret := getTestSecret()
@@ -183,7 +183,7 @@ func TestReconcileInvalidSecretName(t *testing.T) {
183183
NamespacedName: types.NamespacedName{Name: "not-the-secret", Namespace: clusterName},
184184
}
185185
_, err := r.Reconcile(context.TODO(), request)
186-
Expect(err).To(BeNil())
186+
Expect(err).ToNot(HaveOccurred())
187187

188188
// Verify that the Secret was not synced to the managed cluster by the Reconciler.
189189
managedEncryptionSecret := &corev1.Secret{}

controllers/statussync/policy_status_sync.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,9 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
318318
newHistory = append(newHistory, history[historyIndex].ComplianceHistory)
319319

320320
for j := historyIndex; j < len(history); j++ {
321-
if history[historyIndex].EventName == history[j].EventName &&
322-
history[historyIndex].Message == history[j].Message {
323-
// same event, filter it
324-
} else {
321+
// Skip over duplicate statuses where the event name and message match the current status
322+
if history[historyIndex].EventName != history[j].EventName ||
323+
history[historyIndex].Message != history[j].Message {
325324
historyIndex = j - 1
326325

327326
break

controllers/templatesync/template_sync.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -591,22 +591,22 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
591591
}
592592

593593
continue
594-
} else {
595-
// a different error getting template object from cluster
596-
resultError = err
597-
errMsg := fmt.Sprintf("Failed to get the object in the policy template: %s", err)
594+
}
598595

599-
_ = r.emitTemplateError(ctx, instance, tIndex, tName, isClusterScoped, errMsg)
596+
// a different error getting template object from cluster
597+
resultError = err
598+
errMsg := fmt.Sprintf("Failed to get the object in the policy template: %s", err)
600599

601-
tLogger.Error(err, "Failed to get the object in the policy template",
602-
"namespace", instance.GetNamespace(),
603-
"kind", gvk.Kind,
604-
)
600+
_ = r.emitTemplateError(ctx, instance, tIndex, tName, isClusterScoped, errMsg)
601+
602+
tLogger.Error(err, "Failed to get the object in the policy template",
603+
"namespace", instance.GetNamespace(),
604+
"kind", gvk.Kind,
605+
)
605606

606-
policySystemErrorsCounter.WithLabelValues(instance.Name, tName, "get-error").Inc()
607+
policySystemErrorsCounter.WithLabelValues(instance.Name, tName, "get-error").Inc()
607608

608-
continue
609-
}
609+
continue
610610
}
611611

612612
if len(dependencyFailures) > 0 {

0 commit comments

Comments
 (0)