Use error variable for QEMU cluster on non-Linux amd64

This commit is contained in:
Nils Hanke 2022-10-24 18:22:55 +02:00
parent 48d08f4d47
commit 7500eb3e39
6 changed files with 20 additions and 11 deletions

View File

@ -22,6 +22,9 @@ import (
"github.com/edgelesssys/constellation/v2/internal/config"
)
// ErrQEMUCreationNotSupportedOnPlatform is returned when trying to create a QEMU cluster on a platform other than linux/amd64
var ErrQEMUCreationNotSupportedOnPlatform = fmt.Errorf("creation of a QEMU based Constellation is not supported for %s/%s (only linux/amd64 is supported)", runtime.GOOS, runtime.GOARCH)
// Creator creates cloud resources.
type Creator struct {
out io.Writer
@ -73,7 +76,7 @@ func (c *Creator) Create(ctx context.Context, provider cloudprovider.Provider, c
return c.createAzure(ctx, cl, config, name, insType, controlPlaneCount, workerCount)
case cloudprovider.QEMU:
if runtime.GOARCH != "amd64" || runtime.GOOS != "linux" {
return clusterid.File{}, fmt.Errorf("creation of a QEMU based Constellation is not supported for %s/%s", runtime.GOOS, runtime.GOARCH)
return clusterid.File{}, ErrQEMUCreationNotSupportedOnPlatform
}
cl, err := c.newTerraformClient(ctx, provider)
if err != nil {

View File

@ -17,6 +17,9 @@ import (
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
)
// ErrQEMUCreationNotSupportedOnPlatform is returned when trying to destroy a QEMU cluster on a platform other than linux/amd64
var ErrQEMUTerminationNotSupportedOnPlatform = fmt.Errorf("termination of a QEMU based Constellation is not supported for %s/%s (only linux/amd64 is supported)", runtime.GOOS, runtime.GOARCH)
// Terminator deletes cloud provider resources.
type Terminator struct {
newTerraformClient func(ctx context.Context, provider cloudprovider.Provider) (terraformClient, error)
@ -43,7 +46,7 @@ func (t *Terminator) Terminate(ctx context.Context, provider cloudprovider.Provi
if provider == cloudprovider.QEMU {
if runtime.GOARCH != "amd64" || runtime.GOOS != "linux" {
return fmt.Errorf("termination of a QEMU based Constellation is not supported for %s/%s", runtime.GOOS, runtime.GOARCH)
return ErrQEMUTerminationNotSupportedOnPlatform
}
libvirt := t.newLibvirtRunner()

View File

@ -10,6 +10,9 @@ import (
"errors"
"fmt"
"os"
"runtime"
"github.com/edgelesssys/constellation/v2/cli/internal/cloudcmd"
"github.com/edgelesssys/constellation/v2/cli/internal/clusterid"
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
@ -33,6 +36,10 @@ func newMiniDownCmd() *cobra.Command {
}
func runDown(cmd *cobra.Command, args []string) error {
if runtime.GOARCH != "amd64" || runtime.GOOS != "linux" {
return cloudcmd.ErrQEMUTerminationNotSupportedOnPlatform
}
if err := checkForMiniCluster(file.NewHandler(afero.NewOsFs())); err != nil {
return fmt.Errorf("failed to destroy cluster: %w. Are you in the correct working directory?", err)
}

View File

@ -10,9 +10,7 @@ SPDX-License-Identifier: AGPL-3.0-only
package cmd
import (
"fmt"
"runtime"
"github.com/edgelesssys/constellation/v2/cli/internal/cloudcmd"
"github.com/spf13/cobra"
)
@ -29,5 +27,5 @@ func newMiniDownCmd() *cobra.Command {
}
func runDown(cmd *cobra.Command, args []string) error {
return fmt.Errorf("termination of a QEMU based Constellation is not supported for %s/%s", runtime.GOOS, runtime.GOARCH)
return cloudcmd.ErrQEMUTerminationNotSupportedOnPlatform
}

View File

@ -106,7 +106,7 @@ func up(cmd *cobra.Command, creator cloudCreator, spinner spinnerInterf) error {
func checkSystemRequirements(out io.Writer) error {
// check arch/os
if runtime.GOARCH != "amd64" || runtime.GOOS != "linux" {
return fmt.Errorf("creation of a QEMU based Constellation is not supported for %s/%s", runtime.GOOS, runtime.GOARCH)
return cloudcmd.ErrQEMUCreationNotSupportedOnPlatform
}
// check if /dev/kvm exists

View File

@ -10,9 +10,7 @@ SPDX-License-Identifier: AGPL-3.0-only
package cmd
import (
"fmt"
"runtime"
"github.com/edgelesssys/constellation/v2/cli/internal/cloudcmd"
"github.com/spf13/cobra"
)
@ -33,5 +31,5 @@ func newMiniUpCmd() *cobra.Command {
}
func runUp(cmd *cobra.Command, args []string) error {
return fmt.Errorf("creation of a QEMU based Constellation is not supported for %s/%s", runtime.GOOS, runtime.GOARCH)
return cloudcmd.ErrQEMUCreationNotSupportedOnPlatform
}