Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manual sync of package upgrades (#130) #492

Merged
merged 3 commits into from
May 8, 2023
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
2 changes: 1 addition & 1 deletion .ci-operator.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
build_root_image:
name: builder
namespace: stolostron
tag: go1.19-linux
tag: go1.20-linux
10 changes: 0 additions & 10 deletions CHANGELOG/CHANGELOG-v0.8.0.md

This file was deleted.

14 changes: 0 additions & 14 deletions CHANGELOG/CHANGELOG-v0.9.0.md

This file was deleted.

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ fmt:
############################################################

.PHONY: test
test: kubebuilder-dependencies kubebuilder
KUBEBUILDER_ASSETS=$(LOCAL_BIN) go test $(TESTARGS) `go list ./... | grep -v test/e2e`
test: envtest kubebuilder
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test $(TESTARGS) `go list ./... | grep -v test/e2e`

.PHONY: test-coverage
test-coverage: TESTARGS = -json -cover -covermode=atomic -coverprofile=coverage_unit.out
Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright Contributors to the Open Cluster Management project

# Stage 1: Use image builder to build the target binaries
FROM registry.ci.openshift.org/stolostron/builder:go1.19-linux AS builder
FROM registry.ci.openshift.org/stolostron/builder:go1.20-linux AS builder

ENV COMPONENT=config-policy-controller
ENV REPO_PATH=/go/src/github.com/stolostron/${COMPONENT}
Expand Down
24 changes: 11 additions & 13 deletions build/common/Makefile.common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ controller-gen: ## Download controller-gen locally if necessary.

.PHONY: kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,sigs.k8s.io/kustomize/kustomize/v4@v4.5.4)
$(call go-get-tool,sigs.k8s.io/kustomize/kustomize/v5@v5.0.1)

############################################################
# Lint
Expand All @@ -53,7 +53,7 @@ lint: lint-dependencies lint-yaml lint-go

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

.PHONY: lint-yaml
lint-yaml:
Expand All @@ -68,20 +68,22 @@ lint-go:
.PHONY: fmt-dependencies
fmt-dependencies:
$(call go-get-tool,github.com/daixiang0/gci@v0.10.1)
$(call go-get-tool,mvdan.cc/gofumpt@v0.4.0)
$(call go-get-tool,mvdan.cc/gofumpt@v0.5.0)

.PHONY: fmt
fmt: fmt-dependencies
find . -not \( -path "./.go" -prune \) -name "*.go" | xargs gofmt -s -w
find . -not \( -path "./.go" -prune \) -name "*.go" | xargs gofumpt -l -w
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))"

############################################################
# Unit Test
############################################################
KUBEBUILDER = $(LOCAL_BIN)/kubebuilder
KBVERSION = 3.9.1
K8S_VERSION = 1.26.1
GOSEC = $(LOCAL_BIN)/gosec
KUBEBUILDER = $(LOCAL_BIN)/kubebuilder
ENVTEST = $(LOCAL_BIN)/setup-envtest
KBVERSION = 3.12.0
ENVTEST_K8S_VERSION = 1.26.x

.PHONY: kubebuilder
kubebuilder:
Expand All @@ -91,13 +93,9 @@ kubebuilder:
chmod +x $(KUBEBUILDER); \
fi

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

.PHONY: gosec
gosec:
Expand Down
11 changes: 5 additions & 6 deletions controllers/configurationpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ func addConditionToStatus(

// do not add condition unless it does not already appear in the status
if !checkMessageSimilarity(plc.Status.CompliancyDetails[index].Conditions, cond) {
conditions := AppendCondition(plc.Status.CompliancyDetails[index].Conditions, cond, "", false)
conditions := AppendCondition(plc.Status.CompliancyDetails[index].Conditions, cond)
plc.Status.CompliancyDetails[index].Conditions = conditions
updateNeeded = true
}
Expand Down Expand Up @@ -1950,8 +1950,7 @@ func (r *ConfigurationPolicyReconciler) getMapping(
policy.Status.CompliancyDetails[index].ComplianceState = policyv1.NonCompliant

if !checkMessageSimilarity(policy.Status.CompliancyDetails[index].Conditions, cond) {
conditions := AppendCondition(policy.Status.CompliancyDetails[index].Conditions,
cond, gvk.GroupKind().Kind, false)
conditions := AppendCondition(policy.Status.CompliancyDetails[index].Conditions, cond)
policy.Status.CompliancyDetails[index].Conditions = conditions
updateNeeded = true
}
Expand Down Expand Up @@ -2321,10 +2320,10 @@ func mergeArrays(newArr []interface{}, old []interface{}, ctype string) (result
key := fmt.Sprint(val2)
if seen[key] {
continue
} else {
seen[key] = true
}

seen[key] = true

count := 0
val2 := oldItemSet[key].value
// for each list item in the existing array, iterate through the template array and try to find a match
Expand Down Expand Up @@ -2667,7 +2666,7 @@ func (r *ConfigurationPolicyReconciler) checkAndUpdateResource(

// AppendCondition check and appends conditions to the policy status
func AppendCondition(
conditions []policyv1.Condition, newCond *policyv1.Condition, resourceType string, resolved ...bool,
conditions []policyv1.Condition, newCond *policyv1.Condition,
) (conditionsRes []policyv1.Condition) {
defer recoverFlow()

Expand Down
18 changes: 9 additions & 9 deletions controllers/encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ func getReconciler(includeSecret bool) ConfigurationPolicyReconciler {
// Generate AES-256 keys and store them as a secret.
key := make([]byte, keySize/8)
_, err := rand.Read(key)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

previousKey := make([]byte, keySize/8)
_, err = rand.Read(previousKey)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

encryptionSecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestGetEncryptionKey(t *testing.T) {
r := getReconciler(true)
cachedEncryptionKey, err := r.getEncryptionKey(clusterName)

Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(cachedEncryptionKey.key).ToNot(BeNil())
Expect(cachedEncryptionKey.previousKey).ToNot(BeNil())
}
Expand All @@ -86,7 +86,7 @@ func TestGetEncryptionKeyFail(t *testing.T) {
r := getReconciler(false)
cachedEncryptionKey, err := r.getEncryptionKey(clusterName)

Expect(err).ToNot(BeNil())
Expect(err).To(HaveOccurred())
Expect(cachedEncryptionKey).To(BeNil())
}

Expand All @@ -100,7 +100,7 @@ func TestGetEncryptionConfig(t *testing.T) {
policy := getEmptyPolicy()

config, usedCache, err := r.getEncryptionConfig(policy, false)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(usedCache).To(BeFalse())
Expect(config).ToNot(BeNil())
Expect(config.AESKey).ToNot(BeNil())
Expand All @@ -124,13 +124,13 @@ func TestGetEncryptionConfigCached(t *testing.T) {

key := make([]byte, keySize/8)
_, err := rand.Read(key)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())

r.cachedEncryptionKey = &cachedEncryptionKey{key: key}
policy := getEmptyPolicy()

config, usedCache, err := r.getEncryptionConfig(policy, false)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(usedCache).To(BeTrue())
Expect(config).ToNot(BeNil())
Expect(config.AESKey).ToNot(BeNil())
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestGetEncryptionConfigForceRefresh(t *testing.T) {
policy := getEmptyPolicy()

config, usedCache, err := r.getEncryptionConfig(policy, true)
Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(usedCache).To(BeFalse())
Expect(config).ToNot(BeNil())
Expect(config.AESKey).ToNot(Equal(key))
Expand All @@ -214,7 +214,7 @@ func TestGetEncryptionKeyEmptySecret(t *testing.T) {
r := ConfigurationPolicyReconciler{Client: client, DecryptionConcurrency: 5}
cachedEncryptionKey, err := r.getEncryptionKey(clusterName)

Expect(err).To(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(cachedEncryptionKey.key).To(BeNil())
Expect(cachedEncryptionKey.previousKey).To(BeNil())
}
Expand Down
Loading