You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
decort-golang-sdk/pkg/cloudbroker/k8ci/create.go

73 lines
2.0 KiB

3 years ago
package k8ci
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
3 years ago
)
2 years ago
// CreateRequest struct to create K8CI instance
3 years ago
type CreateRequest struct {
// Name of catalog item
// Required: true
3 years ago
Name string `url:"name" json:"name" validate:"required"`
3 years ago
// Version tag
// Required: true
3 years ago
Version string `url:"version" json:"version" validate:"required"`
3 years ago
// Optional description
// Required: false
3 years ago
Description string `url:"description,omitempty" json:"description,omitempty"`
3 years ago
// Image ID for master K8S node
// Required: true
3 years ago
MasterImageID uint64 `url:"masterImageId" json:"masterImageId" validate:"required"`
3 years ago
// Image ID for worker K8S node
// Required: true
3 years ago
WorkerImageID uint64 `url:"workerImageId" json:"workerImageId" validate:"required"`
3 years ago
// List of account IDs, which have access to this item.
// If empty, any account has access
// Required: false
3 years ago
SharedWith []uint64 `url:"sharedWith,omitempty" json:"sharedWith,omitempty"`
3 years ago
// Policy limit on maximum number of master nodes
// Required: true
2 years ago
MaxMasterCount uint64 `url:"maxMasterCount" json:"maxMasterCount" validate:"required"`
3 years ago
// Policy limit on maximum number of worker nodes
// Required: true
2 years ago
MaxWorkerCount uint64 `url:"maxWorkerCount" json:"maxWorkerCount" validate:"required"`
// Network plugins
2 years ago
// Values of slice must be flannel, weavenet or calico
2 years ago
//Required: true
NetworkPlugins []string `url:"networkPlugins" json:"networkPlugins" validate:"required,networkPlugins"`
3 years ago
}
// Create creates a new K8CI instance
func (k K8CI) Create(ctx context.Context, req CreateRequest) (uint64, error) {
3 years ago
err := validators.ValidateRequest(req)
3 years ago
if err != nil {
2 years ago
return 0, validators.ValidationErrors(validators.GetErrors(err))
3 years ago
}
url := "/cloudbroker/k8ci/create"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return 0, err
}
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil {
return 0, err
}
return result, nil
}