package clusterapi import ( "archive/zip" "bytes" "embed" "fmt" "io" "os" "path" "path/filepath" "strings" "github.com/pkg/errors" "github.com/sirupsen/logrus" "k8s.io/apimachinery/pkg/util/sets" ) const ( zipFile = "cluster-api.zip" ) var ( // ClusterAPI is the core provider for cluster-api. ClusterAPI = Provider{ Name: "cluster-api", Sources: sets.New("cluster-api"), } // EnvTest is the provider for the local control plane. EnvTest = Provider{ Name: "envtest", Sources: sets.New("kube-apiserver", "etcd"), } // AWS is the provider for creating resources in AWS. AWS = infrastructureProvider("aws") // Azure is the provider for creating resources in Azure. Azure = infrastructureProvider("azure") // AzureStack is the provider for creating resources in AzureStack. // The AzureStack provider is maintained in an OpenShift fork of CAPZ. AzureStack = infrastructureProvider("azurestack") // AzureASO is a companion component to Azure that is used to create resources declaratively. AzureASO = infrastructureProvider("azureaso") // GCP is the provider for creating resources in GCP. GCP = infrastructureProvider("gcp") // IBMCloud is the provider for creating resources in IBM Cloud and powervs. IBMCloud = infrastructureProvider("ibmcloud") // Nutanix is the provider for creating resources in Nutanix. Nutanix = infrastructureProvider("nutanix") // OpenStack is the provider for creating resources in OpenStack. OpenStack = infrastructureProvider("openstack") // OpenStackORC is a companion component to OpenStack that is used to create resources declaratively. OpenStackORC = infrastructureProvider("openstackorc") // VSphere is the provider for creating resources in vSphere. VSphere = infrastructureProvider("vsphere") ) // Provider is a Cluster API provider. type Provider struct { // Name of the provider. Name string // Sources of the provider. Sources sets.Set[string] } // infrastructureProvider configures a infrastructureProvider built locally. func infrastructureProvider(name string) Provider { return Provider{ Name: name, Sources: sets.New( fmt.Sprintf("cluster-api-provider-%s", name), ), } } // Mirror is the embedded data for the providers. // //go:embed mirror/* var Mirror embed.FS // Extract extracts the provider from the embedded data into the specified directory. func (p Provider) Extract(dir string) error { f, err := Mirror.Open(path.Join("mirror", zipFile)) if err != nil { return errors.Wrap(err, "failed to open cluster api zip from mirror") } defer f.Close() stat, err := f.Stat() if err != nil { return errors.Wrap(err, "failed to stat cluster api zip") } seek, ok := f.(io.ReaderAt) if !ok { // If the file does not support ReaderAt interface (