operator: always create initial resources (#858)

* operator: move csp clients to own path

* operator: use cloudfake as default csp
This commit is contained in:
3u13r 2023-01-04 16:44:47 +01:00 committed by GitHub
parent f720726074
commit 98316b5248
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 112 additions and 108 deletions

View file

@ -44,7 +44,7 @@ func InitialResources(ctx context.Context, k8sClient client.Client, imageInfo im
if err != nil {
return fmt.Errorf("determining initial node image: %w", err)
}
imageVersion, err := imageInfo.ImageVersion(imageReference)
imageVersion, err := imageInfo.ImageVersion()
if err != nil {
// do not fail if the image version cannot be determined
// this is important for backwards compatibility
@ -192,7 +192,7 @@ func createScalingGroup(ctx context.Context, config newScalingGroupConfig) error
}
type imageInfoGetter interface {
ImageVersion(imageReference string) (string, error)
ImageVersion() (string, error)
}
type scalingGroupGetter interface {

View file

@ -393,7 +393,7 @@ type stubImageInfo struct {
err error
}
func (s stubImageInfo) ImageVersion(_ string) (string, error) {
func (s stubImageInfo) ImageVersion() (string, error) {
return s.imageVersion, s.err
}

View file

@ -29,7 +29,7 @@ func NewImageInfo() *ImageInfo {
// ImageVersion tries to parse the image version from the host mounted os-release file.
// If the file is not present or does not contain the version, a fallback lookup is performed.
func (i *ImageInfo) ImageVersion(imageReference string) (string, error) {
func (i *ImageInfo) ImageVersion() (string, error) {
var version string
var err error
for _, path := range osReleasePaths {
@ -38,10 +38,13 @@ func (i *ImageInfo) ImageVersion(imageReference string) (string, error) {
break
}
}
if version != "" {
return version, nil
if err != nil {
return "", err
}
return imageVersionFromFallback(imageReference)
if version == "" {
return "", fmt.Errorf("IMAGE_VERSION not found in %s", strings.Join(osReleasePaths, ", "))
}
return version, nil
}
// getOSReleaseImageVersion reads the os-release file and returns the image version (if present).
@ -94,17 +97,6 @@ func parseOSRelease(osRelease *bufio.Scanner) (map[string]string, error) {
return osReleaseMap, nil
}
// imageVersionFromFallback tries to guess the image version from the image reference.
// It is a fallback mechanism in case the os-release file is not present or does not contain the version.
// This was the case for older images (< v2.3.0).
func imageVersionFromFallback(imageReference string) (string, error) {
version, ok := fallbackLookup[strings.ToLower(imageReference)]
if !ok {
return "", fmt.Errorf("image version not found in fallback lookup")
}
return version, nil
}
const versionKey = "IMAGE_VERSION"
var (
@ -114,41 +106,4 @@ var (
"/host/etc/os-release",
"/host/usr/lib/os-release",
}
fallbackLookup = map[string]string{
// AWS
"ami-06b8cbf4837a0a57c": "v2.2.2",
"ami-02e96dc04a9e438cd": "v2.2.2",
"ami-028ead928a9034b2f": "v2.2.2",
"ami-032ac10dd8d8266e3": "v2.2.1",
"ami-032e0d57cc4395088": "v2.2.1",
"ami-053c3e49e19b96bdd": "v2.2.1",
"ami-0e27ebcefc38f648b": "v2.2.0",
"ami-098cd37f66523b7c3": "v2.2.0",
"ami-04a87d302e2509aad": "v2.2.0",
// Azure
"/communitygalleries/constellationcvm-b3782fa0-0df7-4f2f-963e-fc7fc42663df/images/constellation/versions/2.2.2": "v2.2.2",
"/subscriptions/0d202bbb-4fa7-4af8-8125-58c269a05435/resourcegroups/constellation-images/providers/microsoft.compute/galleries/constellation/images/constellation/versions/2.2.2": "v2.2.2",
"/subscriptions/0d202bbb-4fa7-4af8-8125-58c269a05435/resourcegroups/constellation-images/providers/microsoft.compute/galleries/constellation_cvm/images/constellation/versions/2.2.2": "v2.2.2",
"/communitygalleries/constellationcvm-b3782fa0-0df7-4f2f-963e-fc7fc42663df/images/constellation/versions/2.2.1": "v2.2.1",
"/subscriptions/0d202bbb-4fa7-4af8-8125-58c269a05435/resourcegroups/constellation-images/providers/microsoft.compute/galleries/constellation/images/constellation/versions/2.2.1": "v2.2.1",
"/subscriptions/0d202bbb-4fa7-4af8-8125-58c269a05435/resourcegroups/constellation-images/providers/microsoft.compute/galleries/constellation_cvm/images/constellation/versions/2.2.1": "v2.2.1",
"/communitygalleries/constellationcvm-b3782fa0-0df7-4f2f-963e-fc7fc42663df/images/constellation/versions/2.2.0": "v2.2.0",
"/subscriptions/0d202bbb-4fa7-4af8-8125-58c269a05435/resourcegroups/constellation-images/providers/microsoft.compute/galleries/constellation/images/constellation/versions/2.2.0": "v2.2.0",
"/subscriptions/0d202bbb-4fa7-4af8-8125-58c269a05435/resourcegroups/constellation-images/providers/microsoft.compute/galleries/constellation_cvm/images/constellation/versions/2.2.0": "v2.2.0",
"/communitygalleries/constellationcvm-b3782fa0-0df7-4f2f-963e-fc7fc42663df/images/constellation/versions/2.1.0": "v2.1.0",
"/subscriptions/0d202bbb-4fa7-4af8-8125-58c269a05435/resourcegroups/constellation-images/providers/microsoft.compute/galleries/constellation/images/constellation/versions/2.1.0": "v2.1.0",
"/subscriptions/0d202bbb-4fa7-4af8-8125-58c269a05435/resourcegroups/constellation-images/providers/microsoft.compute/galleries/constellation_cvm/images/constellation/versions/2.1.0": "v2.1.0",
"/communitygalleries/constellationcvm-b3782fa0-0df7-4f2f-963e-fc7fc42663df/images/constellation/versions/2.0.0": "v2.0.0",
"/subscriptions/0d202bbb-4fa7-4af8-8125-58c269a05435/resourcegroups/constellation-images/providers/microsoft.compute/galleries/constellation/images/constellation/versions/2.0.0": "v2.0.0",
"/subscriptions/0d202bbb-4fa7-4af8-8125-58c269a05435/resourcegroups/constellation-images/providers/microsoft.compute/galleries/constellation_cvm/images/constellation/versions/2.0.0": "v2.0.0",
// GCP
"projects/constellation-images/global/images/constellation-v2-2-2": "v2.2.2",
"projects/constellation-images/global/images/constellation-v2-2-1": "v2.2.1",
"projects/constellation-images/global/images/constellation-v2-2-0": "v2.2.0",
"projects/constellation-images/global/images/constellation-v2-1-0": "v2.1.0",
"projects/constellation-images/global/images/constellation-v2-0-0": "v2.0.0",
}
)

View file

@ -38,10 +38,6 @@ func TestImageVersion(t *testing.T) {
imageReference: "some-reference",
wantErr: true,
},
"fallback version found": {
imageReference: "ami-04a87d302e2509aad",
wantVersion: "v2.2.0",
},
}
for name, tc := range testCases {
@ -59,7 +55,7 @@ func TestImageVersion(t *testing.T) {
fs: &afero.Afero{Fs: fs},
}
version, err := imageInfo.ImageVersion(tc.imageReference)
version, err := imageInfo.ImageVersion()
if tc.wantErr {
assert.Error(err)
return
@ -124,46 +120,6 @@ func TestParseOSRelease(t *testing.T) {
assert.Equal(wantMap, osReleaseMap)
}
func TestImageVersionFromFallback(t *testing.T) {
testCases := map[string]struct {
imageReference string
wantVersion string
wantErr bool
}{
"AWS reference": {
imageReference: "ami-06b8cbf4837a0a57c",
wantVersion: "v2.2.2",
},
"Azure reference": {
imageReference: "/subscriptions/0d202bbb-4fa7-4af8-8125-58c269a05435/resourceGroups/constellation-images/providers/Microsoft.Compute/galleries/Constellation/images/constellation/versions/2.1.0",
wantVersion: "v2.1.0",
},
"GCP reference": {
imageReference: "projects/constellation-images/global/images/constellation-v2-0-0",
wantVersion: "v2.0.0",
},
"unknown reference": {
imageReference: "unknown",
wantErr: true,
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
version, err := imageVersionFromFallback(tc.imageReference)
if tc.wantErr {
assert.Error(err)
return
}
require.NoError(err)
assert.Equal(tc.wantVersion, version)
})
}
}
const osRelease = `
# Some comment
# Some empty lines below