kubevela/pkg/cloudprovider/cluster.go

49 lines
1.7 KiB
Go
Raw Permalink Normal View History

/*
Copyright 2021 The KubeVela Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cloudprovider
import (
2021-11-04 16:39:32 +08:00
"context"
"github.com/pkg/errors"
2021-11-04 16:39:32 +08:00
"sigs.k8s.io/controller-runtime/pkg/client"
)
const (
// CloudClusterCreatorLabelKey labels the creator of cloud cluster
CloudClusterCreatorLabelKey = "api.core.oam.dev/cloud-cluster-creator"
)
// CloudClusterProvider abstracts the cloud provider to provide cluster access
type CloudClusterProvider interface {
2021-11-02 09:49:52 +08:00
IsInvalidKey(err error) bool
ListCloudClusters(pageNumber int, pageSize int) ([]*CloudCluster, int, error)
GetClusterKubeConfig(clusterID string) (string, error)
GetClusterInfo(clusterID string) (*CloudCluster, error)
2021-11-04 16:39:32 +08:00
CreateCloudCluster(ctx context.Context, clusterName string, zone string, worker int, cpu int64, mem int64) (string, error)
}
// GetClusterProvider creates interface for getting cloud cluster provider
2021-11-04 16:39:32 +08:00
func GetClusterProvider(provider string, accessKeyID string, accessKeySecret string, k8sClient client.Client) (CloudClusterProvider, error) {
switch provider {
case ProviderAliyun:
2021-11-04 16:39:32 +08:00
return NewAliyunCloudProvider(accessKeyID, accessKeySecret, k8sClient)
default:
return nil, errors.Errorf("cluster provider %s is not implemented", provider)
}
}