Skip to content
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
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ linters:
disabled: true
- name: useless-break
- name: use-any
disabled: true
- name: var-declaration
- name: var-naming
disabled: true
Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ goimport:
test: fmt vet goimport ## Run unit tests
go test ./pkg/... -coverprofile cover.out

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.35.0
ENVTEST = $(shell pwd)/bin/setup-envtest
GINKGO = $(shell pwd)/bin/ginkgo

Expand All @@ -32,6 +30,10 @@ GINKGO = $(shell pwd)/bin/ginkgo
# which is how the sub-module is published and what `go install @<branch>` resolves to.
CONTROLLER_RUNTIME_BRANCH := $(shell grep 'sigs.k8s.io/controller-runtime ' go.mod | awk '{print $$2}' | sed 's/v\([0-9]*\.[0-9]*\)\..*/release-\1/')
GINKGO_VERSION := $(shell grep 'github.com/onsi/ginkgo/v2 ' go.mod | awk '{print $$2}')
# k8s.io/client-go v0.X.Y → envtest Kubernetes version 1.X.0
ENVTEST_K8S_VERSION := $(shell grep 'k8s.io/client-go ' go.mod | awk '{print $$2}' | sed 's/v0\.\([0-9]*\)\..*/1.\1.0/')
# Go toolchain constraint for golangci-lint, matched to the go directive in go.mod
GOTOOLCHAIN := go$(shell grep '^go ' go.mod | awk '{print $$2}')

.PHONY: test-integration
test-integration: envtest ginkgo ## Run integration tests with envtest
Expand Down Expand Up @@ -174,7 +176,7 @@ lint: ## Run golangci-lint
echo "golangci-lint v2 not found. Installing..."; \
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest; \
fi
$(GOLANGCI_LINT) run
GOTOOLCHAIN=$(GOTOOLCHAIN) $(GOLANGCI_LINT) run

SHELLCHECK ?= $(shell which shellcheck)

Expand Down
6 changes: 3 additions & 3 deletions pkg/assets/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ func ParseYAML(data []byte) (*unstructured.Unstructured, error) {
}

// calculateDepth recursively calculates the maximum nesting depth of a map structure
func calculateDepth(obj interface{}) int {
func calculateDepth(obj any) int {
switch v := obj.(type) {
case map[string]interface{}:
case map[string]any:
maxDepth := 0
for _, value := range v {
depth := calculateDepth(value)
Expand All @@ -161,7 +161,7 @@ func calculateDepth(obj interface{}) int {
}
}
return 1 + maxDepth
case []interface{}:
case []any:
maxDepth := 0
for _, item := range v {
depth := calculateDepth(item)
Expand Down
46 changes: 23 additions & 23 deletions pkg/assets/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func TestLoader_ListAssets(t *testing.T) {
func TestCalculateDepth(t *testing.T) {
tests := []struct {
name string
obj interface{}
obj any
expectedMax int
description string
}{
Expand All @@ -384,13 +384,13 @@ func TestCalculateDepth(t *testing.T) {
},
{
name: "empty map",
obj: map[string]interface{}{},
obj: map[string]any{},
expectedMax: 1,
description: "Empty map has depth 1",
},
{
name: "flat map",
obj: map[string]interface{}{
obj: map[string]any{
"key1": "value1",
"key2": "value2",
},
Expand All @@ -399,9 +399,9 @@ func TestCalculateDepth(t *testing.T) {
},
{
name: "nested map",
obj: map[string]interface{}{
"level1": map[string]interface{}{
"level2": map[string]interface{}{
obj: map[string]any{
"level1": map[string]any{
"level2": map[string]any{
"level3": "value",
},
},
Expand All @@ -411,7 +411,7 @@ func TestCalculateDepth(t *testing.T) {
},
{
name: "array of strings",
obj: []interface{}{
obj: []any{
"item1",
"item2",
},
Expand All @@ -420,8 +420,8 @@ func TestCalculateDepth(t *testing.T) {
},
{
name: "array of maps",
obj: []interface{}{
map[string]interface{}{
obj: []any{
map[string]any{
"nested": "value",
},
},
Expand All @@ -430,19 +430,19 @@ func TestCalculateDepth(t *testing.T) {
},
{
name: "complex nested structure",
obj: map[string]interface{}{
"metadata": map[string]interface{}{
obj: map[string]any{
"metadata": map[string]any{
"name": "test",
"labels": map[string]interface{}{
"labels": map[string]any{
"app": "myapp",
},
},
"spec": map[string]interface{}{
"spec": map[string]any{
"replicas": 3,
"template": map[string]interface{}{
"spec": map[string]interface{}{
"containers": []interface{}{
map[string]interface{}{
"template": map[string]any{
"spec": map[string]any{
"containers": []any{
map[string]any{
"name": "nginx",
"image": "nginx:latest",
},
Expand All @@ -456,17 +456,17 @@ func TestCalculateDepth(t *testing.T) {
},
{
name: "empty array",
obj: []interface{}{},
obj: []any{},
expectedMax: 1,
description: "Empty array has depth 1",
},
{
name: "deeply nested maps",
obj: map[string]interface{}{
"l1": map[string]interface{}{
"l2": map[string]interface{}{
"l3": map[string]interface{}{
"l4": map[string]interface{}{
obj: map[string]any{
"l1": map[string]any{
"l2": map[string]any{
"l3": map[string]any{
"l4": map[string]any{
"l5": "deep",
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/assets/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func extractRequiredCRD(content []byte, isTemplate bool) string {
if doc == "" {
continue
}
var obj map[string]interface{}
var obj map[string]any
if err := yaml.Unmarshal([]byte(doc), &obj); err != nil {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/context/render_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ type TopologyContext struct {
}

// AsMap converts TopologyContext to a flat map for condition evaluation.
func (t *TopologyContext) AsMap() map[string]interface{} {
return map[string]interface{}{
func (t *TopologyContext) AsMap() map[string]any {
return map[string]any{
"isHCP": t.IsHCP,
"isCompact": t.IsCompact,
"controlPlaneTopology": t.ControlPlaneTopology,
Expand Down
12 changes: 6 additions & 6 deletions pkg/controller/hco_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,14 @@ func workerOnlyNode(name string) corev1.Node {
}

func infraCR(cpTopology, platformType string) *unstructured.Unstructured {
status := map[string]interface{}{"controlPlaneTopology": cpTopology}
status := map[string]any{"controlPlaneTopology": cpTopology}
if platformType != "" {
status["platformStatus"] = map[string]interface{}{"type": platformType}
status["platformStatus"] = map[string]any{"type": platformType}
}
return &unstructured.Unstructured{Object: map[string]interface{}{
return &unstructured.Unstructured{Object: map[string]any{
"apiVersion": "config.openshift.io/v1",
"kind": "Infrastructure",
"metadata": map[string]interface{}{"name": "cluster"},
"metadata": map[string]any{"name": "cluster"},
"status": status,
}}
}
Expand Down Expand Up @@ -640,10 +640,10 @@ func TestRenderContextBuilder_Build(t *testing.T) {
builder := NewRenderContextBuilder(fakeClient)

hco := &unstructured.Unstructured{
Object: map[string]interface{}{
Object: map[string]any{
"apiVersion": "hco.kubevirt.io/v1",
"kind": "HyperConverged",
"metadata": map[string]interface{}{
"metadata": map[string]any{
"name": "test-hco",
"namespace": "test-namespace",
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/debug/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ func (s *Server) writeRenderResponse(w http.ResponseWriter, outputs []pkgrender.

// writeResponse writes the response in the requested format (used for
// non-render endpoints such as /debug/exclusions and /debug/tombstones).
func (s *Server) writeResponse(w http.ResponseWriter, data interface{}, format string) {
func (s *Server) writeResponse(w http.ResponseWriter, data any, format string) {
var contentType string
var output []byte
var err error
Expand Down
28 changes: 14 additions & 14 deletions pkg/engine/applier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ func TestHasManagedByLabel(t *testing.T) {
{
name: "has correct managed-by label",
obj: &unstructured.Unstructured{
Object: map[string]interface{}{
"metadata": map[string]interface{}{
"labels": map[string]interface{}{
Object: map[string]any{
"metadata": map[string]any{
"labels": map[string]any{
ManagedByLabel: ManagedByValue,
},
},
Expand All @@ -44,9 +44,9 @@ func TestHasManagedByLabel(t *testing.T) {
{
name: "has label with wrong value",
obj: &unstructured.Unstructured{
Object: map[string]interface{}{
"metadata": map[string]interface{}{
"labels": map[string]interface{}{
Object: map[string]any{
"metadata": map[string]any{
"labels": map[string]any{
ManagedByLabel: "wrong-value",
},
},
Expand All @@ -57,18 +57,18 @@ func TestHasManagedByLabel(t *testing.T) {
{
name: "has no labels",
obj: &unstructured.Unstructured{
Object: map[string]interface{}{
"metadata": map[string]interface{}{},
Object: map[string]any{
"metadata": map[string]any{},
},
},
want: false,
},
{
name: "has other labels but not managed-by",
obj: &unstructured.Unstructured{
Object: map[string]interface{}{
"metadata": map[string]interface{}{
"labels": map[string]interface{}{
Object: map[string]any{
"metadata": map[string]any{
"labels": map[string]any{
"app": "test",
},
},
Expand All @@ -79,9 +79,9 @@ func TestHasManagedByLabel(t *testing.T) {
{
name: "has managed-by label among others",
obj: &unstructured.Unstructured{
Object: map[string]interface{}{
"metadata": map[string]interface{}{
"labels": map[string]interface{}{
Object: map[string]any{
"metadata": map[string]any{
"labels": map[string]any{
"app": "test",
ManagedByLabel: ManagedByValue,
"environment": "prod",
Expand Down
20 changes: 10 additions & 10 deletions pkg/engine/drift.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ func (d *DriftDetector) SimpleDriftCheck(desired, live *unstructured.Unstructure
}

// sanitizeObject removes fields that should not be compared for drift
func sanitizeObject(obj *unstructured.Unstructured) map[string]interface{} {
func sanitizeObject(obj *unstructured.Unstructured) map[string]any {
if obj == nil {
return nil
}

sanitized := obj.DeepCopy().Object

// Remove metadata fields that change on every update
if metadata, ok := sanitized["metadata"].(map[string]interface{}); ok {
if metadata, ok := sanitized["metadata"].(map[string]any); ok {
// Keep: name, namespace, labels, annotations
// Remove: resourceVersion, generation, uid, creationTimestamp, managedFields, etc.
fieldsToKeep := map[string]bool{
Expand All @@ -123,7 +123,7 @@ func sanitizeObject(obj *unstructured.Unstructured) map[string]interface{} {
"annotations": true,
}

sanitizedMetadata := make(map[string]interface{})
sanitizedMetadata := make(map[string]any)
for key, value := range metadata {
if fieldsToKeep[key] {
sanitizedMetadata[key] = value
Expand All @@ -142,29 +142,29 @@ func sanitizeObject(obj *unstructured.Unstructured) map[string]interface{} {
// structuredDiff returns a map containing only the fields that differ between
// live and desired. Leaf differences are represented as {"live": <v>, "desired": <v>},
// so the result can be logged directly as a structured value.
func structuredDiff(live, desired map[string]interface{}) map[string]interface{} {
result := make(map[string]interface{})
func structuredDiff(live, desired map[string]any) map[string]any {
result := make(map[string]any)

for k, liveVal := range live {
desiredVal, ok := desired[k]
if !ok {
result[k] = map[string]interface{}{"live": liveVal, "desired": nil}
result[k] = map[string]any{"live": liveVal, "desired": nil}
continue
}
liveMap, liveIsMap := liveVal.(map[string]interface{})
desiredMap, desiredIsMap := desiredVal.(map[string]interface{})
liveMap, liveIsMap := liveVal.(map[string]any)
desiredMap, desiredIsMap := desiredVal.(map[string]any)
if liveIsMap && desiredIsMap {
if sub := structuredDiff(liveMap, desiredMap); len(sub) > 0 {
result[k] = sub
}
} else if !equality.Semantic.DeepEqual(liveVal, desiredVal) {
result[k] = map[string]interface{}{"live": liveVal, "desired": desiredVal}
result[k] = map[string]any{"live": liveVal, "desired": desiredVal}
}
}

for k, desiredVal := range desired {
if _, ok := live[k]; !ok {
result[k] = map[string]interface{}{"live": nil, "desired": desiredVal}
result[k] = map[string]any{"live": nil, "desired": desiredVal}
}
}

Expand Down
Loading