Skip to content

Commit

Permalink
wait for operations
Browse files Browse the repository at this point in the history
  • Loading branch information
sauterp committed Mar 8, 2024
1 parent fb13543 commit 1417605
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 37 deletions.
11 changes: 5 additions & 6 deletions internal/integ/cluster/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c *Cluster) provisionSKSCluster(zone string) error {
return err
}

newCluster, err := c.Ego.CreateSKSCluster(c.context, exov3.CreateSKSClusterRequest{
newClusterID, err := c.awaitID(c.Ego.CreateSKSCluster(c.context, exov3.CreateSKSClusterRequest{
Addons: []string{
"exoscale-cloud-controller",
},
Expand All @@ -66,21 +66,20 @@ func (c *Cluster) provisionSKSCluster(zone string) error {
Name: c.Name,
Level: exov3.CreateSKSClusterRequestLevelPro,
Version: latestSKSVersion,
})
}))
if err != nil {
return err
}

c.ID = newCluster.ID
c.ID = newClusterID

_, err = c.Ego.CreateSKSNodepool(c.context, newCluster.ID, exov3.CreateSKSNodepoolRequest{
if err = c.awaitSuccess(c.Ego.CreateSKSNodepool(c.context, newClusterID, exov3.CreateSKSNodepoolRequest{
Name: c.Name + "-nodepool",
DiskSize: int64(20),
Size: int64(2),
InstancePrefix: "pool",
InstanceType: instanceType,
})
if err != nil {
})); err != nil {
// this can error even when the nodepool is successfully created
// it's probably a bug, so we're not returning the error
slog.Warn("error creating nodepool", "err", err)
Expand Down
14 changes: 11 additions & 3 deletions internal/integ/cluster/teardown.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,21 @@ func (c *Cluster) tearDownCluster() error {
return c.awaitSuccess(c.Ego.DeleteSKSCluster(c.context, cluster.ID))
}

func (c *Cluster) awaitSuccess(op *exov3.Operation, err error) error {
func (c *Cluster) awaitID(op *exov3.Operation, err error) (exov3.UUID, error) {
if err != nil {
return err
return "", err
}

_, err = c.Ego.Wait(c.context, op, exov3.OperationStateSuccess)
ref, err := c.Ego.Wait(c.context, op, exov3.OperationStateSuccess)
if err != nil {
return "", err
}

return ref.ID, nil
}

func (c *Cluster) awaitSuccess(op *exov3.Operation, err error) error {
_, err = c.awaitID(op, err)
return err
}

Expand Down
34 changes: 6 additions & 28 deletions internal/integ/cluster/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,6 @@ func ptr[T any](v T) *T {
return &v
}

func getCredentialsFromEnv() (string, string, error) {
errmsg := "environment variable %q is required"

apiKey := ""
apiSecret := ""

value, ok := os.LookupEnv(util.APIKeyEnvVar)
if !ok {
return "", "", fmt.Errorf(errmsg, util.APIKeyEnvVar)
}
apiKey = value

value, ok = os.LookupEnv(util.APISecretEnvVar)
if !ok {
return "", "", fmt.Errorf(errmsg, util.APIKeyEnvVar)
}
apiSecret = value

return apiKey, apiSecret, nil
}

func (c *Cluster) getClusterID() (exov3.UUID, error) {
if err := flags.ValidateFlags(); err != nil {
return "", err
Expand All @@ -91,7 +70,7 @@ func (c *Cluster) getClusterID() (exov3.UUID, error) {
}
}

return "", fmt.Errorf("failed to find cluster", "name", *flags.ClusterName)
return "", fmt.Errorf("failed to find cluster named %q", *flags.ClusterName)
}

func (c *Cluster) getCluster() (*exov3.SKSCluster, error) {
Expand Down Expand Up @@ -228,7 +207,7 @@ func (c *Cluster) createImagePullSecret() {
}

func (c *Cluster) applyCSI() error {
// TODO (sauterp) reenable or remove once it is clear which registy should be used for the test images
// TODO (sauterp) reenable or remove once it is clear which registry should be used for the test images
// c.createImagePullSecret()

if *flags.CreateCSISecret {
Expand All @@ -240,7 +219,7 @@ func (c *Cluster) applyCSI() error {
Type: exov3.IAMServicePolicyTypeAllow,
}

role, err := c.Ego.CreateIAMRole(c.context, exov3.CreateIAMRoleRequest{
roleID, err := c.awaitID(c.Ego.CreateIAMRole(c.context, exov3.CreateIAMRoleRequest{
Name: c.APIRoleName,
Description: "role for the CSI test cluster " + c.Name,
Editable: ptr(false),
Expand All @@ -250,14 +229,14 @@ func (c *Cluster) applyCSI() error {
"compute": allow,
},
},
})
}))
if err != nil {
return fmt.Errorf("error creating IAM role: %w", err)
}

apiKey, err := c.Ego.CreateAPIKey(c.context, exov3.CreateAPIKeyRequest{
Name: c.APIKeyName,
RoleID: role.ID,
RoleID: roleID,
})
if err != nil {
return err
Expand All @@ -280,8 +259,7 @@ func (c *Cluster) applyCSI() error {
}
}

// TODO(sauterp) this shouldn't be necessary anymore once the CSI addon is available.
// the CSI controller needs to restart to pick up the new secrets
// the CSI controller needs to restart, in case it is already running, to pick up the new secrets
c.restartCSIController()

controllerName := "exoscale-csi-controller"
Expand Down

0 comments on commit 1417605

Please sign in to comment.