From 98316b5248f56bb6899a20fbef49a583e15f5fe3 Mon Sep 17 00:00:00 2001 From: 3u13r Date: Wed, 4 Jan 2023 16:44:47 +0100 Subject: [PATCH] operator: always create initial resources (#858) * operator: move csp clients to own path * operator: use cloudfake as default csp --- .../internal/{ => cloud}/azure/client/api.go | 0 .../{ => cloud}/azure/client/autoscaler.go | 0 .../{ => cloud}/azure/client/client.go | 0 .../{ => cloud}/azure/client/client_test.go | 0 .../{ => cloud}/azure/client/config.go | 0 .../{ => cloud}/azure/client/config_test.go | 0 .../{ => cloud}/azure/client/instanceview.go | 0 .../azure/client/instanceview_test.go | 0 .../{ => cloud}/azure/client/nodeimage.go | 0 .../azure/client/nodeimage_test.go | 0 .../{ => cloud}/azure/client/pendingnode.go | 0 .../azure/client/pendingnode_test.go | 0 .../{ => cloud}/azure/client/providerid.go | 0 .../azure/client/providerid_test.go | 0 .../{ => cloud}/azure/client/scalinggroup.go | 0 .../azure/client/scalinggroup_test.go | 0 .../internal/{ => cloud}/azure/client/vmss.go | 0 .../{ => cloud}/azure/client/vmss_test.go | 0 .../internal/cloud/fake/client/client.go | 91 +++++++++++++++++++ .../internal/{ => cloud}/gcp/client/api.go | 0 .../{ => cloud}/gcp/client/autocaler.go | 0 .../internal/{ => cloud}/gcp/client/client.go | 0 .../{ => cloud}/gcp/client/client_test.go | 0 .../internal/{ => cloud}/gcp/client/config.go | 0 .../{ => cloud}/gcp/client/config_test.go | 0 .../internal/{ => cloud}/gcp/client/disks.go | 0 .../{ => cloud}/gcp/client/disks_test.go | 0 .../{ => cloud}/gcp/client/gcpwrappers.go | 0 .../gcp/client/instancegroupmanagers.go | 0 .../gcp/client/instancegroupmanagers_test.go | 0 .../gcp/client/instancetemplate.go | 0 .../gcp/client/instancetemplate_test.go | 0 .../{ => cloud}/gcp/client/metadata.go | 0 .../{ => cloud}/gcp/client/metadata_test.go | 0 .../{ => cloud}/gcp/client/nodeimage.go | 0 .../{ => cloud}/gcp/client/nodeimage_test.go | 0 .../{ => cloud}/gcp/client/pendingnode.go | 0 .../gcp/client/pendingnode_test.go | 0 .../{ => cloud}/gcp/client/project.go | 0 .../{ => cloud}/gcp/client/project_test.go | 0 .../{ => cloud}/gcp/client/providerid.go | 0 .../{ => cloud}/gcp/client/providerid_test.go | 0 .../{ => cloud}/gcp/client/scalinggroup.go | 0 .../gcp/client/scalinggroup_test.go | 0 .../internal/deploy/deploy.go | 4 +- .../internal/deploy/deploy_test.go | 2 +- .../internal/deploy/imageinfo.go | 59 ++---------- .../internal/deploy/imageinfo_test.go | 46 +--------- operators/constellation-node-operator/main.go | 18 ++-- 49 files changed, 112 insertions(+), 108 deletions(-) rename operators/constellation-node-operator/internal/{ => cloud}/azure/client/api.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/azure/client/autoscaler.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/azure/client/client.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/azure/client/client_test.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/azure/client/config.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/azure/client/config_test.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/azure/client/instanceview.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/azure/client/instanceview_test.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/azure/client/nodeimage.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/azure/client/nodeimage_test.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/azure/client/pendingnode.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/azure/client/pendingnode_test.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/azure/client/providerid.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/azure/client/providerid_test.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/azure/client/scalinggroup.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/azure/client/scalinggroup_test.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/azure/client/vmss.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/azure/client/vmss_test.go (100%) create mode 100644 operators/constellation-node-operator/internal/cloud/fake/client/client.go rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/api.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/autocaler.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/client.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/client_test.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/config.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/config_test.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/disks.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/disks_test.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/gcpwrappers.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/instancegroupmanagers.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/instancegroupmanagers_test.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/instancetemplate.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/instancetemplate_test.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/metadata.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/metadata_test.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/nodeimage.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/nodeimage_test.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/pendingnode.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/pendingnode_test.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/project.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/project_test.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/providerid.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/providerid_test.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/scalinggroup.go (100%) rename operators/constellation-node-operator/internal/{ => cloud}/gcp/client/scalinggroup_test.go (100%) diff --git a/operators/constellation-node-operator/internal/azure/client/api.go b/operators/constellation-node-operator/internal/cloud/azure/client/api.go similarity index 100% rename from operators/constellation-node-operator/internal/azure/client/api.go rename to operators/constellation-node-operator/internal/cloud/azure/client/api.go diff --git a/operators/constellation-node-operator/internal/azure/client/autoscaler.go b/operators/constellation-node-operator/internal/cloud/azure/client/autoscaler.go similarity index 100% rename from operators/constellation-node-operator/internal/azure/client/autoscaler.go rename to operators/constellation-node-operator/internal/cloud/azure/client/autoscaler.go diff --git a/operators/constellation-node-operator/internal/azure/client/client.go b/operators/constellation-node-operator/internal/cloud/azure/client/client.go similarity index 100% rename from operators/constellation-node-operator/internal/azure/client/client.go rename to operators/constellation-node-operator/internal/cloud/azure/client/client.go diff --git a/operators/constellation-node-operator/internal/azure/client/client_test.go b/operators/constellation-node-operator/internal/cloud/azure/client/client_test.go similarity index 100% rename from operators/constellation-node-operator/internal/azure/client/client_test.go rename to operators/constellation-node-operator/internal/cloud/azure/client/client_test.go diff --git a/operators/constellation-node-operator/internal/azure/client/config.go b/operators/constellation-node-operator/internal/cloud/azure/client/config.go similarity index 100% rename from operators/constellation-node-operator/internal/azure/client/config.go rename to operators/constellation-node-operator/internal/cloud/azure/client/config.go diff --git a/operators/constellation-node-operator/internal/azure/client/config_test.go b/operators/constellation-node-operator/internal/cloud/azure/client/config_test.go similarity index 100% rename from operators/constellation-node-operator/internal/azure/client/config_test.go rename to operators/constellation-node-operator/internal/cloud/azure/client/config_test.go diff --git a/operators/constellation-node-operator/internal/azure/client/instanceview.go b/operators/constellation-node-operator/internal/cloud/azure/client/instanceview.go similarity index 100% rename from operators/constellation-node-operator/internal/azure/client/instanceview.go rename to operators/constellation-node-operator/internal/cloud/azure/client/instanceview.go diff --git a/operators/constellation-node-operator/internal/azure/client/instanceview_test.go b/operators/constellation-node-operator/internal/cloud/azure/client/instanceview_test.go similarity index 100% rename from operators/constellation-node-operator/internal/azure/client/instanceview_test.go rename to operators/constellation-node-operator/internal/cloud/azure/client/instanceview_test.go diff --git a/operators/constellation-node-operator/internal/azure/client/nodeimage.go b/operators/constellation-node-operator/internal/cloud/azure/client/nodeimage.go similarity index 100% rename from operators/constellation-node-operator/internal/azure/client/nodeimage.go rename to operators/constellation-node-operator/internal/cloud/azure/client/nodeimage.go diff --git a/operators/constellation-node-operator/internal/azure/client/nodeimage_test.go b/operators/constellation-node-operator/internal/cloud/azure/client/nodeimage_test.go similarity index 100% rename from operators/constellation-node-operator/internal/azure/client/nodeimage_test.go rename to operators/constellation-node-operator/internal/cloud/azure/client/nodeimage_test.go diff --git a/operators/constellation-node-operator/internal/azure/client/pendingnode.go b/operators/constellation-node-operator/internal/cloud/azure/client/pendingnode.go similarity index 100% rename from operators/constellation-node-operator/internal/azure/client/pendingnode.go rename to operators/constellation-node-operator/internal/cloud/azure/client/pendingnode.go diff --git a/operators/constellation-node-operator/internal/azure/client/pendingnode_test.go b/operators/constellation-node-operator/internal/cloud/azure/client/pendingnode_test.go similarity index 100% rename from operators/constellation-node-operator/internal/azure/client/pendingnode_test.go rename to operators/constellation-node-operator/internal/cloud/azure/client/pendingnode_test.go diff --git a/operators/constellation-node-operator/internal/azure/client/providerid.go b/operators/constellation-node-operator/internal/cloud/azure/client/providerid.go similarity index 100% rename from operators/constellation-node-operator/internal/azure/client/providerid.go rename to operators/constellation-node-operator/internal/cloud/azure/client/providerid.go diff --git a/operators/constellation-node-operator/internal/azure/client/providerid_test.go b/operators/constellation-node-operator/internal/cloud/azure/client/providerid_test.go similarity index 100% rename from operators/constellation-node-operator/internal/azure/client/providerid_test.go rename to operators/constellation-node-operator/internal/cloud/azure/client/providerid_test.go diff --git a/operators/constellation-node-operator/internal/azure/client/scalinggroup.go b/operators/constellation-node-operator/internal/cloud/azure/client/scalinggroup.go similarity index 100% rename from operators/constellation-node-operator/internal/azure/client/scalinggroup.go rename to operators/constellation-node-operator/internal/cloud/azure/client/scalinggroup.go diff --git a/operators/constellation-node-operator/internal/azure/client/scalinggroup_test.go b/operators/constellation-node-operator/internal/cloud/azure/client/scalinggroup_test.go similarity index 100% rename from operators/constellation-node-operator/internal/azure/client/scalinggroup_test.go rename to operators/constellation-node-operator/internal/cloud/azure/client/scalinggroup_test.go diff --git a/operators/constellation-node-operator/internal/azure/client/vmss.go b/operators/constellation-node-operator/internal/cloud/azure/client/vmss.go similarity index 100% rename from operators/constellation-node-operator/internal/azure/client/vmss.go rename to operators/constellation-node-operator/internal/cloud/azure/client/vmss.go diff --git a/operators/constellation-node-operator/internal/azure/client/vmss_test.go b/operators/constellation-node-operator/internal/cloud/azure/client/vmss_test.go similarity index 100% rename from operators/constellation-node-operator/internal/azure/client/vmss_test.go rename to operators/constellation-node-operator/internal/cloud/azure/client/vmss_test.go diff --git a/operators/constellation-node-operator/internal/cloud/fake/client/client.go b/operators/constellation-node-operator/internal/cloud/fake/client/client.go new file mode 100644 index 000000000..c0532965c --- /dev/null +++ b/operators/constellation-node-operator/internal/cloud/fake/client/client.go @@ -0,0 +1,91 @@ +/* +Copyright (c) Edgeless Systems GmbH + +SPDX-License-Identifier: AGPL-3.0-only +*/ + +package client + +import ( + "context" + "fmt" + + updatev1alpha1 "github.com/edgelesssys/constellation/operators/constellation-node-operator/v2/api/v1alpha1" +) + +const ( + controlPlanesID = "control-planes-id" + workersID = "workers-id" +) + +// Client is a stub client providing the minimal implementation to set up the initial resources. +type Client struct{} + +// GetNodeImage retrieves the image currently used by a node. +func (c *Client) GetNodeImage(ctx context.Context, providerID string) (string, error) { + panic("not implemented") +} + +// GetScalingGroupID retrieves the scaling group that a node is part of. +func (c *Client) GetScalingGroupID(ctx context.Context, providerID string) (string, error) { + panic("not implemented") +} + +// CreateNode creates a new node inside a specified scaling group at the CSP and returns its future name and provider id. +func (c *Client) CreateNode(ctx context.Context, scalingGroupID string) (nodeName, providerID string, err error) { + panic("not implemented") +} + +// DeleteNode starts the termination of the node at the CSP. +func (c *Client) DeleteNode(ctx context.Context, providerID string) error { + panic("not implemented") +} + +// GetNodeState retrieves the state of a pending node from a CSP. +func (c *Client) GetNodeState(ctx context.Context, providerID string) (updatev1alpha1.CSPNodeState, error) { + panic("not implemented") +} + +// SetScalingGroupImage sets the image to be used by newly created nodes in a scaling group. +func (c *Client) SetScalingGroupImage(ctx context.Context, scalingGroupID, image string) error { + panic("not implemented") +} + +// GetScalingGroupImage retrieves the image currently used by a scaling group. +func (c *Client) GetScalingGroupImage(ctx context.Context, scalingGroupID string) (string, error) { + return "unsupportedCSP", nil +} + +// GetScalingGroupName retrieves the name of a scaling group. +func (c *Client) GetScalingGroupName(scalingGroupID string) (string, error) { + switch scalingGroupID { + case controlPlanesID: + return controlPlanesID, nil + case workersID: + return workersID, nil + default: + return "", fmt.Errorf("unknown scaling group id %s", scalingGroupID) + } +} + +// GetAutoscalingGroupName retrieves the name of a scaling group as needed by the cluster-autoscaler. +func (c *Client) GetAutoscalingGroupName(scalingGroupID string) (string, error) { + switch scalingGroupID { + case controlPlanesID: + return controlPlanesID, nil + case workersID: + return workersID, nil + default: + return "", fmt.Errorf("unknown scaling group id %s", scalingGroupID) + } +} + +// ListScalingGroups retrieves a list of scaling groups for the cluster. +func (c *Client) ListScalingGroups(ctx context.Context, uid string) (controlPlaneGroupIDs []string, workerGroupIDs []string, err error) { + return []string{controlPlanesID}, []string{workersID}, nil +} + +// AutoscalingCloudProvider returns the cloud-provider name as used by k8s cluster-autoscaler. +func (c *Client) AutoscalingCloudProvider() string { + return "unsupportedCSP" +} diff --git a/operators/constellation-node-operator/internal/gcp/client/api.go b/operators/constellation-node-operator/internal/cloud/gcp/client/api.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/api.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/api.go diff --git a/operators/constellation-node-operator/internal/gcp/client/autocaler.go b/operators/constellation-node-operator/internal/cloud/gcp/client/autocaler.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/autocaler.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/autocaler.go diff --git a/operators/constellation-node-operator/internal/gcp/client/client.go b/operators/constellation-node-operator/internal/cloud/gcp/client/client.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/client.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/client.go diff --git a/operators/constellation-node-operator/internal/gcp/client/client_test.go b/operators/constellation-node-operator/internal/cloud/gcp/client/client_test.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/client_test.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/client_test.go diff --git a/operators/constellation-node-operator/internal/gcp/client/config.go b/operators/constellation-node-operator/internal/cloud/gcp/client/config.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/config.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/config.go diff --git a/operators/constellation-node-operator/internal/gcp/client/config_test.go b/operators/constellation-node-operator/internal/cloud/gcp/client/config_test.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/config_test.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/config_test.go diff --git a/operators/constellation-node-operator/internal/gcp/client/disks.go b/operators/constellation-node-operator/internal/cloud/gcp/client/disks.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/disks.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/disks.go diff --git a/operators/constellation-node-operator/internal/gcp/client/disks_test.go b/operators/constellation-node-operator/internal/cloud/gcp/client/disks_test.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/disks_test.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/disks_test.go diff --git a/operators/constellation-node-operator/internal/gcp/client/gcpwrappers.go b/operators/constellation-node-operator/internal/cloud/gcp/client/gcpwrappers.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/gcpwrappers.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/gcpwrappers.go diff --git a/operators/constellation-node-operator/internal/gcp/client/instancegroupmanagers.go b/operators/constellation-node-operator/internal/cloud/gcp/client/instancegroupmanagers.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/instancegroupmanagers.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/instancegroupmanagers.go diff --git a/operators/constellation-node-operator/internal/gcp/client/instancegroupmanagers_test.go b/operators/constellation-node-operator/internal/cloud/gcp/client/instancegroupmanagers_test.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/instancegroupmanagers_test.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/instancegroupmanagers_test.go diff --git a/operators/constellation-node-operator/internal/gcp/client/instancetemplate.go b/operators/constellation-node-operator/internal/cloud/gcp/client/instancetemplate.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/instancetemplate.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/instancetemplate.go diff --git a/operators/constellation-node-operator/internal/gcp/client/instancetemplate_test.go b/operators/constellation-node-operator/internal/cloud/gcp/client/instancetemplate_test.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/instancetemplate_test.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/instancetemplate_test.go diff --git a/operators/constellation-node-operator/internal/gcp/client/metadata.go b/operators/constellation-node-operator/internal/cloud/gcp/client/metadata.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/metadata.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/metadata.go diff --git a/operators/constellation-node-operator/internal/gcp/client/metadata_test.go b/operators/constellation-node-operator/internal/cloud/gcp/client/metadata_test.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/metadata_test.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/metadata_test.go diff --git a/operators/constellation-node-operator/internal/gcp/client/nodeimage.go b/operators/constellation-node-operator/internal/cloud/gcp/client/nodeimage.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/nodeimage.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/nodeimage.go diff --git a/operators/constellation-node-operator/internal/gcp/client/nodeimage_test.go b/operators/constellation-node-operator/internal/cloud/gcp/client/nodeimage_test.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/nodeimage_test.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/nodeimage_test.go diff --git a/operators/constellation-node-operator/internal/gcp/client/pendingnode.go b/operators/constellation-node-operator/internal/cloud/gcp/client/pendingnode.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/pendingnode.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/pendingnode.go diff --git a/operators/constellation-node-operator/internal/gcp/client/pendingnode_test.go b/operators/constellation-node-operator/internal/cloud/gcp/client/pendingnode_test.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/pendingnode_test.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/pendingnode_test.go diff --git a/operators/constellation-node-operator/internal/gcp/client/project.go b/operators/constellation-node-operator/internal/cloud/gcp/client/project.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/project.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/project.go diff --git a/operators/constellation-node-operator/internal/gcp/client/project_test.go b/operators/constellation-node-operator/internal/cloud/gcp/client/project_test.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/project_test.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/project_test.go diff --git a/operators/constellation-node-operator/internal/gcp/client/providerid.go b/operators/constellation-node-operator/internal/cloud/gcp/client/providerid.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/providerid.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/providerid.go diff --git a/operators/constellation-node-operator/internal/gcp/client/providerid_test.go b/operators/constellation-node-operator/internal/cloud/gcp/client/providerid_test.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/providerid_test.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/providerid_test.go diff --git a/operators/constellation-node-operator/internal/gcp/client/scalinggroup.go b/operators/constellation-node-operator/internal/cloud/gcp/client/scalinggroup.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/scalinggroup.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/scalinggroup.go diff --git a/operators/constellation-node-operator/internal/gcp/client/scalinggroup_test.go b/operators/constellation-node-operator/internal/cloud/gcp/client/scalinggroup_test.go similarity index 100% rename from operators/constellation-node-operator/internal/gcp/client/scalinggroup_test.go rename to operators/constellation-node-operator/internal/cloud/gcp/client/scalinggroup_test.go diff --git a/operators/constellation-node-operator/internal/deploy/deploy.go b/operators/constellation-node-operator/internal/deploy/deploy.go index eee86195e..52e58fec8 100644 --- a/operators/constellation-node-operator/internal/deploy/deploy.go +++ b/operators/constellation-node-operator/internal/deploy/deploy.go @@ -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 { diff --git a/operators/constellation-node-operator/internal/deploy/deploy_test.go b/operators/constellation-node-operator/internal/deploy/deploy_test.go index fbe929710..cde5c36b0 100644 --- a/operators/constellation-node-operator/internal/deploy/deploy_test.go +++ b/operators/constellation-node-operator/internal/deploy/deploy_test.go @@ -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 } diff --git a/operators/constellation-node-operator/internal/deploy/imageinfo.go b/operators/constellation-node-operator/internal/deploy/imageinfo.go index 5119f64a9..bcfd5e912 100644 --- a/operators/constellation-node-operator/internal/deploy/imageinfo.go +++ b/operators/constellation-node-operator/internal/deploy/imageinfo.go @@ -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", - } ) diff --git a/operators/constellation-node-operator/internal/deploy/imageinfo_test.go b/operators/constellation-node-operator/internal/deploy/imageinfo_test.go index 485da6ea1..e5a98b292 100644 --- a/operators/constellation-node-operator/internal/deploy/imageinfo_test.go +++ b/operators/constellation-node-operator/internal/deploy/imageinfo_test.go @@ -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 diff --git a/operators/constellation-node-operator/main.go b/operators/constellation-node-operator/main.go index 0e26eec44..bd0d25b4c 100644 --- a/operators/constellation-node-operator/main.go +++ b/operators/constellation-node-operator/main.go @@ -24,9 +24,10 @@ import ( "sigs.k8s.io/controller-runtime/pkg/healthz" "sigs.k8s.io/controller-runtime/pkg/log/zap" - azureclient "github.com/edgelesssys/constellation/operators/constellation-node-operator/v2/internal/azure/client" + azureclient "github.com/edgelesssys/constellation/operators/constellation-node-operator/v2/internal/cloud/azure/client" + cloudfake "github.com/edgelesssys/constellation/operators/constellation-node-operator/v2/internal/cloud/fake/client" + gcpclient "github.com/edgelesssys/constellation/operators/constellation-node-operator/v2/internal/cloud/gcp/client" "github.com/edgelesssys/constellation/operators/constellation-node-operator/v2/internal/deploy" - gcpclient "github.com/edgelesssys/constellation/operators/constellation-node-operator/v2/internal/gcp/client" updatev1alpha1 "github.com/edgelesssys/constellation/operators/constellation-node-operator/v2/api/v1alpha1" "github.com/edgelesssys/constellation/operators/constellation-node-operator/v2/controllers" @@ -100,6 +101,7 @@ func main() { } default: setupLog.Info("CSP does not support upgrades", "csp", csp) + cspClient = &cloudfake.Client{} } mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ @@ -127,13 +129,13 @@ func main() { } defer etcdClient.Close() + imageInfo := deploy.NewImageInfo() + if err := deploy.InitialResources(context.Background(), k8sClient, imageInfo, cspClient, os.Getenv(constellationUID)); err != nil { + setupLog.Error(err, "Unable to deploy initial resources") + os.Exit(1) + } // Create Controllers if csp == "azure" || csp == "gcp" { - imageInfo := deploy.NewImageInfo() - if err := deploy.InitialResources(context.Background(), k8sClient, imageInfo, cspClient, os.Getenv(constellationUID)); err != nil { - setupLog.Error(err, "Unable to deploy initial resources") - os.Exit(1) - } if err = controllers.NewNodeVersionReconciler( cspClient, etcdClient, mgr.GetClient(), mgr.GetScheme(), ).SetupWithManager(mgr); err != nil { @@ -204,7 +206,7 @@ type cspAPI interface { SetScalingGroupImage(ctx context.Context, scalingGroupID, imageURI string) error // GetScalingGroupName retrieves the name of a scaling group. GetScalingGroupName(scalingGroupID string) (string, error) - // GetScalingGroupName retrieves the name of a scaling group as needed by the cluster-autoscaler. + // GetAutoscalingGroupName retrieves the name of a scaling group as needed by the cluster-autoscaler. GetAutoscalingGroupName(scalingGroupID string) (string, error) // ListScalingGroups retrieves a list of scaling groups for the cluster. ListScalingGroups(ctx context.Context, uid string) (controlPlaneGroupIDs []string, workerGroupIDs []string, err error)