forked from gardener/gardener
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcloudprofile_test.go
More file actions
172 lines (144 loc) · 5.05 KB
/
cloudprofile_test.go
File metadata and controls
172 lines (144 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// SPDX-FileCopyrightText: SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package worker_test
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/gardener/gardener/extensions/pkg/controller/worker"
gardencorev1beta1 "github.com/gardener/gardener/pkg/apis/core/v1beta1"
)
// ProviderImageFlavor is a test implementation of the ImageFlavor interface.
type ProviderImageFlavor struct {
Name string
Capabilities gardencorev1beta1.Capabilities
}
// GetCapabilities returns the capabilities of the image flavor.
func (t ProviderImageFlavor) GetCapabilities() gardencorev1beta1.Capabilities {
return t.Capabilities
}
var _ = Describe("Worker", func() {
Describe("#FindBestImageFlavor", func() {
var (
capabilityDefinitions []gardencorev1beta1.CapabilityDefinition
imageFlavors []ProviderImageFlavor
)
BeforeEach(func() {
capabilityDefinitions = []gardencorev1beta1.CapabilityDefinition{
{
Name: "architecture",
Values: []string{"amd64", "arm64"},
},
{
Name: "foo",
Values: []string{"bar", "baz", "qux", "xxx"},
},
}
imageFlavors = []ProviderImageFlavor{
{
Name: "amd64-set",
Capabilities: gardencorev1beta1.Capabilities{
"foo": []string{"bar", "qux"},
"architecture": []string{"amd64"},
},
},
{
Name: "amd64-set-2",
Capabilities: gardencorev1beta1.Capabilities{
"foo": []string{"bar", "baz"},
"architecture": []string{"amd64"},
},
},
{
Name: "arm64-set",
Capabilities: gardencorev1beta1.Capabilities{
"foo": []string{"bar", "baz", "qux"},
"architecture": []string{"arm64"},
},
},
}
})
It("should find an exact matching version flavor", func() {
// Request only matches first version flavor
requestedCapabilities := gardencorev1beta1.Capabilities{
"architecture": []string{"amd64"},
"foo": []string{"qux"},
}
result, err := FindBestImageFlavor(imageFlavors, requestedCapabilities, capabilityDefinitions)
Expect(err).NotTo(HaveOccurred())
Expect(result.Name).To(Equal("amd64-set"))
})
It("should find best match based on capability priorities", func() {
// Both sets are compatible, but the first one is preferred due to "amd64" having higher priority
requestedCapabilities := gardencorev1beta1.Capabilities{
"foo": []string{"qux"},
}
result, err := FindBestImageFlavor(imageFlavors, requestedCapabilities, capabilityDefinitions)
Expect(err).NotTo(HaveOccurred())
Expect(result.Name).To(Equal("amd64-set"))
})
It("should return error when no compatible flavor is found", func() {
// Requested capabilities not compatible with any set
requestedCapabilities := gardencorev1beta1.Capabilities{
"architecture": []string{"arm64"},
"foo": []string{"xxx"}, // arm64 set only has "bar" "baz" and "qux"
}
_, err := FindBestImageFlavor(imageFlavors, requestedCapabilities, capabilityDefinitions)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("no compatible flavor found"))
})
It("should find the most appropriate set based on capability value preferences", func() {
requestedCapabilities := gardencorev1beta1.Capabilities{
"architecture": []string{"amd64"},
"foo": []string{"bar"},
}
result, err := FindBestImageFlavor(imageFlavors, requestedCapabilities, capabilityDefinitions)
Expect(err).NotTo(HaveOccurred())
Expect(result.Name).To(Equal("amd64-set-2"))
})
It("should prioritize capabilities based on their order in definitions", func() {
// Reorder definitions to prioritize "foo" over "architecture"
reorderedDefinitions := []gardencorev1beta1.CapabilityDefinition{
{
Name: "foo",
Values: []string{"bar", "baz", "qux"},
},
{
Name: "architecture",
Values: []string{"amd64", "arm64"},
},
}
requestedCapabilities := gardencorev1beta1.Capabilities{
"foo": []string{"bar"},
}
result, err := FindBestImageFlavor(imageFlavors, requestedCapabilities, reorderedDefinitions)
Expect(err).NotTo(HaveOccurred())
Expect(result.Name).To(Equal("arm64-set")) // "baz" has higher preference in foo values
})
It("should handle capabilities with multiple values", func() {
multiValueSets := []*ProviderImageFlavor{
{
Name: "bar-baz",
Capabilities: gardencorev1beta1.Capabilities{
"architecture": []string{"amd64"},
"foo": []string{"bar", "baz"},
},
},
{
Name: "bar-baz-qux",
Capabilities: gardencorev1beta1.Capabilities{
"architecture": []string{"amd64"},
"foo": []string{"bar", "baz", "qux"},
},
},
}
requestedCapabilities := gardencorev1beta1.Capabilities{
"architecture": []string{"amd64"},
"foo": []string{"bar"},
}
result, err := FindBestImageFlavor(multiValueSets, requestedCapabilities, capabilityDefinitions)
Expect(err).NotTo(HaveOccurred())
Expect(result.Name).To(Equal("bar-baz-qux"))
})
})
})