Skip to content

Commit

Permalink
test: build provisioners based on build tags
Browse files Browse the repository at this point in the history
Fixes confidential-containers#695

Signed-off-by: Yohei Ueda <[email protected]>
  • Loading branch information
yoheiueda committed Mar 10, 2023
1 parent 867ff31 commit 95f2772
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 32 deletions.
23 changes: 8 additions & 15 deletions test/provisioner/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ type CloudProvisioner interface {
UploadPodvm(imagePath string, ctx context.Context, cfg *envconf.Config) error
}

type newProvisionerFunc func(properties map[string]string) (CloudProvisioner, error)

var newProvisionerFunctions = make(map[string]newProvisionerFunc)

type CloudAPIAdaptor struct {
caaDaemonSet *appsv1.DaemonSet // Represents the cloud-api-adaptor daemonset
ccDaemonSet *appsv1.DaemonSet // Represents the CoCo installer daemonset
Expand Down Expand Up @@ -59,13 +63,8 @@ func NewCloudAPIAdaptor(provider string) (p *CloudAPIAdaptor) {

// GetCloudProvisioner returns a CloudProvisioner implementation
func GetCloudProvisioner(provider string, propertiesFile string) (CloudProvisioner, error) {
var (
err error
properties map[string]string
provisioner CloudProvisioner
)

properties = make(map[string]string)
properties := make(map[string]string)
if propertiesFile != "" {
f, err := os.ReadFile(propertiesFile)
if err != nil {
Expand All @@ -76,18 +75,12 @@ func GetCloudProvisioner(provider string, propertiesFile string) (CloudProvision
}
}

switch provider {
case "azure":
provisioner, err = NewAzureCloudProvisioner("default", "default")
case "libvirt":
provisioner, err = NewLibvirtProvisioner(properties)
case "ibmcloud":
provisioner, err = NewIBMCloudProvisioner(properties)
default:
newProvisioner, ok := newProvisionerFunctions[provider]
if !ok {
return nil, fmt.Errorf("Not implemented provisioner for %s\n", provider)
}

return provisioner, err
return newProvisioner(properties)
}

// Deletes the peer pods installation including the controller manager.
Expand Down
11 changes: 9 additions & 2 deletions test/provisioner/provision_azure.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
//go:build azure

// (C) Copyright Confidential Containers Contributors
// SPDX-License-Identifier: Apache-2.0

package provisioner

import (
"context"

"sigs.k8s.io/e2e-framework/pkg/envconf"
)

// AzureCloudProvisioner implements the CloudProvisioner interface for ibmcloud.
func init() {
newProvisionerFunctions["azure"] = NewAzureCloudProvisioner
}

// AzureCloudProvisioner implements the CloudProvisioner interface for Azure.
type AzureCloudProvisioner struct {
}

func NewAzureCloudProvisioner(network string, storage string) (*AzureCloudProvisioner, error) {
func NewAzureCloudProvisioner(properties map[string]string) (CloudProvisioner, error) {
return &AzureCloudProvisioner{}, nil
}

Expand Down
9 changes: 8 additions & 1 deletion test/provisioner/provision_ibmcloud.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build ibmcloud

// (C) Copyright Confidential Containers Contributors
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -9,10 +11,11 @@ import (
"fmt"
"os"
"path/filepath"
"sigs.k8s.io/e2e-framework/pkg/envconf"
"strings"
"time"

"sigs.k8s.io/e2e-framework/pkg/envconf"

"github.com/confidential-containers/cloud-api-adaptor/test/utils"

"github.com/IBM-Cloud/bluemix-go/api/container/containerv2"
Expand All @@ -24,6 +27,10 @@ import (
log "github.com/sirupsen/logrus"
)

func init() {
newProvisionerFunctions["ibmcloud"] = NewIBMCloudProvisioner
}

// https://cloud.ibm.com/docs/vpc?topic=vpc-configuring-address-prefixes
func getCidrBlock(region, zone string) string {
switch region {
Expand Down
2 changes: 2 additions & 0 deletions test/provisioner/provision_ibmcloud_initializer.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build ibmcloud

// (C) Copyright Confidential Containers Contributors
// SPDX-License-Identifier: Apache-2.0

Expand Down
3 changes: 3 additions & 0 deletions test/provisioner/provision_ibmcloud_self_mgr.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
//go:build ibmcloud

// (C) Copyright Confidential Containers Contributors
// SPDX-License-Identifier: Apache-2.0

package provisioner

import (
"context"

"sigs.k8s.io/e2e-framework/pkg/envconf"
)

Expand Down
13 changes: 9 additions & 4 deletions test/provisioner/provision_libvirt.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build cgo
//go:build libvirt && cgo

// (C) Copyright Confidential Containers Contributors
// SPDX-License-Identifier: Apache-2.0
Expand All @@ -8,15 +8,20 @@ package provisioner
import (
"context"
"fmt"
"libvirt.org/go/libvirt"
"libvirt.org/go/libvirtxml"
"os"
"os/exec"
"path"
"path/filepath"

"libvirt.org/go/libvirt"
"libvirt.org/go/libvirtxml"
"sigs.k8s.io/e2e-framework/pkg/envconf"
)

func init() {
newProvisionerFunctions["libvirt"] = NewLibvirtProvisioner
}

// LibvirtProvisioner implements the CloudProvisioner interface for Libvirt.
type LibvirtProvisioner struct {
conn *libvirt.Connect // Libvirt connection
Expand All @@ -26,7 +31,7 @@ type LibvirtProvisioner struct {
volumeName string // Podvm volume name
}

func NewLibvirtProvisioner(properties map[string]string) (*LibvirtProvisioner, error) {
func NewLibvirtProvisioner(properties map[string]string) (CloudProvisioner, error) {
wd, err := filepath.Abs(path.Join("..", "..", "libvirt"))
if err != nil {
return nil, err
Expand Down
10 changes: 0 additions & 10 deletions test/provisioner/provision_libvirt_nocgo.go

This file was deleted.

0 comments on commit 95f2772

Please sign in to comment.