github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/cli/cloudprovider/interface.go (about)

     1  /*
     2  Copyright (C) 2022-2023 ApeCloud Co., Ltd
     3  
     4  This file is part of KubeBlocks project
     5  
     6  This program is free software: you can redistribute it and/or modify
     7  it under the terms of the GNU Affero General Public License as published by
     8  the Free Software Foundation, either version 3 of the License, or
     9  (at your option) any later version.
    10  
    11  This program is distributed in the hope that it will be useful
    12  but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  GNU Affero General Public License for more details.
    15  
    16  You should have received a copy of the GNU Affero General Public License
    17  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    18  */
    19  
    20  package cloudprovider
    21  
    22  import (
    23  	"fmt"
    24  	"io"
    25  
    26  	"github.com/pkg/errors"
    27  )
    28  
    29  type Interface interface {
    30  	// Name returns the cloud provider name
    31  	Name() string
    32  
    33  	// CreateK8sCluster creates a kubernetes cluster
    34  	CreateK8sCluster(clusterInfo *K8sClusterInfo) error
    35  
    36  	// DeleteK8sCluster deletes the created kubernetes cluster
    37  	DeleteK8sCluster(clusterInfo *K8sClusterInfo) error
    38  
    39  	// GetClusterInfo gets cluster info
    40  	GetClusterInfo() (*K8sClusterInfo, error)
    41  }
    42  
    43  func New(provider, tfRootPath string, stdout, stderr io.Writer) (Interface, error) {
    44  	switch provider {
    45  	case AWS, TencentCloud, AliCloud, GCP:
    46  		return newCloudProvider(provider, tfRootPath, stdout, stderr)
    47  	case Local:
    48  		return newLocalCloudProvider(stdout, stderr), nil
    49  	default:
    50  		return nil, errors.New(fmt.Sprintf("Unknown cloud provider %s", provider))
    51  	}
    52  }