From 8b44c2661aba6896c5547777012be7e0cde24838 Mon Sep 17 00:00:00 2001 From: Robert Hoppe Date: Sun, 3 Mar 2024 22:52:20 +0100 Subject: [PATCH] Introduce latest changes for SKE 1.1 (#211) Co-authored-by: Robert Hoppe --- internal/config/kubernetes/v1.1/config.yaml | 85 + internal/config/kubernetes/v1.1/generate.go | 3 + .../kubernetes/v1.1/include/cluster/common.go | 14 + .../v1.1/include/cluster/validate.go | 187 ++ .../kubernetes/v1.1/include/cluster/wait.go | 59 + .../kubernetes/v1.1/include/project/common.go | 14 + .../kubernetes/v1.1/include/project/wait.go | 60 + .../config/kubernetes/v1.1/include/service.go | 17 + .../config/kubernetes/v1.1/kubernetes.json | 2418 +++++++++++++++++ .../kubernetes/v1.1/cluster/cluster.go | 1517 +++++++++++ .../kubernetes/v1.1/cluster/validate.go | 186 ++ pkg/services/kubernetes/v1.1/cluster/wait.go | 58 + .../v1.1/credentials/credentials.go | 912 +++++++ pkg/services/kubernetes/v1.1/kubernetes.go | 115 + .../kubernetes/v1.1/operation/operation.go | 1328 +++++++++ .../kubernetes/v1.1/project/project.go | 547 ++++ pkg/services/kubernetes/v1.1/project/wait.go | 59 + .../v1.1/provider-options/provider-options.go | 313 +++ pkg/services/kubernetes/v1.1/service.go | 16 + 19 files changed, 7908 insertions(+) create mode 100644 internal/config/kubernetes/v1.1/config.yaml create mode 100644 internal/config/kubernetes/v1.1/generate.go create mode 100644 internal/config/kubernetes/v1.1/include/cluster/common.go create mode 100644 internal/config/kubernetes/v1.1/include/cluster/validate.go create mode 100644 internal/config/kubernetes/v1.1/include/cluster/wait.go create mode 100644 internal/config/kubernetes/v1.1/include/project/common.go create mode 100644 internal/config/kubernetes/v1.1/include/project/wait.go create mode 100644 internal/config/kubernetes/v1.1/include/service.go create mode 100644 internal/config/kubernetes/v1.1/kubernetes.json create mode 100644 pkg/services/kubernetes/v1.1/cluster/cluster.go create mode 100644 pkg/services/kubernetes/v1.1/cluster/validate.go create mode 100644 pkg/services/kubernetes/v1.1/cluster/wait.go create mode 100644 pkg/services/kubernetes/v1.1/credentials/credentials.go create mode 100644 pkg/services/kubernetes/v1.1/kubernetes.go create mode 100644 pkg/services/kubernetes/v1.1/operation/operation.go create mode 100644 pkg/services/kubernetes/v1.1/project/project.go create mode 100644 pkg/services/kubernetes/v1.1/project/wait.go create mode 100644 pkg/services/kubernetes/v1.1/provider-options/provider-options.go create mode 100644 pkg/services/kubernetes/v1.1/service.go diff --git a/internal/config/kubernetes/v1.1/config.yaml b/internal/config/kubernetes/v1.1/config.yaml new file mode 100644 index 00000000..b602071e --- /dev/null +++ b/internal/config/kubernetes/v1.1/config.yaml @@ -0,0 +1,85 @@ +package: kubernetes +output: ../../../../pkg/services/kubernetes/v1.1/kubernetes.go +generate: + models: true + client: true +output-options: + custom-doer: + enabled: true + import: contracts "github.com/SchwarzIT/community-stackit-go-client/pkg/contracts" + name: "contracts.BaseClientInterface" + split-by-tags: + verbose: false + enabled: true + extend-response: + - field: Error + type: error + description: "Aggregated error" + apply-to: ["*"] + imports: ["github.com/SchwarzIT/community-stackit-go-client/pkg/validate"] + set: "validate.DefaultResponseErrorHandler(rsp)" + copy: + - from: include/cluster/wait.go + to: cluster/wait.go + tidy: + - replace: "cluster." + all: true + - from: include/cluster/validate.go + to: cluster/validate.go + tidy: + - replace: "cluster." + all: true + - from: include/service.go + to: service.go + tidy: + - replace: "kubernetes." + all: true + - from: include/project/wait.go + to: project/wait.go + tidy: + - replace: "project." + all: true +tidy: + verbose: false + functions: + - replace: SkeService + with: + prefix: true + - replace: Clusters + with: + suffix: true + - replace: Cluster + with: + suffix: true + - replace: TriggerCluster + with: Trigger + prefix: true + - replace: GetClusterCredentials + with: List + prefix: true + - replace: TriggerCredentialRotation + with: TriggerRotation + prefix: true + - replace: Project + with: + suffix: true + - replace: GetProviderOptions + with: List + prefix: true + params: + - replace: Id + with: ID + suffix: true + schemas: + - replace: v1 + with: + prefix: true + - replace: Id + with: ID + suffix: true + - replace: Cri + with: CRI + match: true + - replace: Cpu + with: CPU + match: true diff --git a/internal/config/kubernetes/v1.1/generate.go b/internal/config/kubernetes/v1.1/generate.go new file mode 100644 index 00000000..16a461b4 --- /dev/null +++ b/internal/config/kubernetes/v1.1/generate.go @@ -0,0 +1,3 @@ +package gen + +//go:generate go run github.com/do87/stackit-client-generator/cmd/oapi-codegen@v0.0.2 -config config.yaml kubernetes.json diff --git a/internal/config/kubernetes/v1.1/include/cluster/common.go b/internal/config/kubernetes/v1.1/include/cluster/common.go new file mode 100644 index 00000000..147fd4ae --- /dev/null +++ b/internal/config/kubernetes/v1.1/include/cluster/common.go @@ -0,0 +1,14 @@ +// this file is only used to prevent wait.go +// from showing errors + +package cluster + +import "github.com/SchwarzIT/community-stackit-go-client/pkg/services/kubernetes/v1.1/cluster" + +type CreateOrUpdateResponse struct { + cluster.ClientWithResponsesInterface +} + +type DeleteResponse struct { + cluster.ClientWithResponsesInterface +} diff --git a/internal/config/kubernetes/v1.1/include/cluster/validate.go b/internal/config/kubernetes/v1.1/include/cluster/validate.go new file mode 100644 index 00000000..86349c15 --- /dev/null +++ b/internal/config/kubernetes/v1.1/include/cluster/validate.go @@ -0,0 +1,187 @@ +// this file is used for validating cluster data and properties + +package cluster + +import ( + "errors" + "fmt" + "regexp" + + "github.com/SchwarzIT/community-stackit-go-client/pkg/services/kubernetes/v1.1/cluster" + "github.com/SchwarzIT/community-stackit-go-client/pkg/validate" +) + +// Validate validates the given cluster data (dry validation) +func Validate( + clusterName string, + clusterConfig cluster.Kubernetes, + nodePools []cluster.Nodepool, + maintenance *cluster.Maintenance, + hibernation *cluster.Hibernation, + extensions *cluster.Extension, +) error { + if err := validate.SemVer(clusterConfig.Version); err != nil { + return err + } + if err := ValidateClusterName(clusterName); err != nil { + return err + } + if len(nodePools) == 0 { + return errors.New("at least one node pool must be specified") + } + for _, np := range nodePools { + if err := ValidateNodePool(np); err != nil { + return err + } + } + if err := ValidateMaintenance(maintenance); err != nil { + return err + } + if err := ValidateHibernation(hibernation); err != nil { + return err + } + if err := ValidateExtensions(extensions); err != nil { + return err + } + return nil +} + +// ValidateClusterName validates a given cluster name +func ValidateClusterName(name string) error { + exp := `^[a-z0-9]{1}[a-z0-9-]{0,10}$` + r := regexp.MustCompile(exp) + if !r.MatchString(name) { + return fmt.Errorf("invalid cluster name. valid name is of: %s", exp) + } + return nil +} + +// ValidateNodePoolName validates a given pool name +func ValidateNodePoolName(name string) error { + exp := `^[a-z0-9]{1}[a-z0-9-]{0,14}$` + r := regexp.MustCompile(exp) + if !r.MatchString(name) { + return fmt.Errorf("invalid node pool name. valid name is of: %s", exp) + } + return nil +} + +// ValidateNodePool validates a given node pool +func ValidateNodePool(np cluster.Nodepool) error { + if err := ValidateNodePoolName(np.Name); err != nil { + return err + } + if np.Machine.Type == "" { + return errors.New("machine type must be specified") + } + if np.Machine.Image.Version == "" { + return errors.New("machine image version must be specified") + } + if np.Minimum > np.Maximum { + return errors.New("minimum value can't be larger than maximum") + } + if np.Minimum < 1 || np.Minimum > 100 { + return errors.New("minimum value must be in the range of 1..100") + } + if np.Maximum < 1 || np.Maximum > 100 { + return errors.New("maximum value must be in the range of 1..100") + } + if np.MaxSurge != nil { + if *np.MaxSurge < 1 || *np.MaxSurge > 10 { + return errors.New("max surge value must be in the range of 1..10") + } + } + if np.Volume.Size < 20 || np.Volume.Size > 10240 { + return errors.New("volume size value must be in the range of 20..10240") + } + if np.Taints != nil { + for _, t := range *np.Taints { + if err := ValidateTaint(t); err != nil { + return err + } + } + } + if err := ValidateCRI(np.CRI); err != nil { + return err + } + return nil +} + +// ValidateTaint validates a given node pool taint +func ValidateTaint(t cluster.Taint) error { + switch t.Effect { + case cluster.NO_EXECUTE: + fallthrough + case cluster.NO_SCHEDULE: + fallthrough + case cluster.PREFER_NO_SCHEDULE: + default: + return fmt.Errorf("invalid taint effect '%s'", t.Effect) + } + + if t.Key == "" { + return errors.New("taint key is required") + } + return nil +} + +// ValidateCRI validates the given cri struct +func ValidateCRI(c *cluster.CRI) error { + if c == nil { + return nil + } + if c.Name == nil { + return nil + } + switch *c.Name { + case cluster.CONTAINERD: + fallthrough + case cluster.DOCKER: + default: + return fmt.Errorf("invalid CRI name '%s'", string(*c.Name)) + } + return nil +} + +// ValidateMaintenance validates a given cluster maintenance +func ValidateMaintenance(m *cluster.Maintenance) error { + if m == nil { + return nil + } + if m.TimeWindow.End == "" { + return errors.New("maintenance end time window is required") + } + if m.TimeWindow.Start == "" { + return errors.New("maintenance start time window is required") + } + return nil +} + +// ValidateHibernation validates a given cluster hibernation +func ValidateHibernation(h *cluster.Hibernation) error { + if h == nil { + return nil + } + for _, s := range h.Schedules { + if s.End == "" { + return errors.New("hibernation end time is required") + } + if s.Start == "" { + return errors.New("hibernation start time is required") + } + } + return nil +} + +// ValidateExtensions validates a given cluster extensions +func ValidateExtensions(e *cluster.Extension) error { + if e == nil { + return nil + } + if e.Argus != nil { + if e.Argus.Enabled && e.Argus.ArgusInstanceID == "" { + return errors.New("argus instance ID is mandatory when Argus is enabled") + } + } + return nil +} diff --git a/internal/config/kubernetes/v1.1/include/cluster/wait.go b/internal/config/kubernetes/v1.1/include/cluster/wait.go new file mode 100644 index 00000000..c6303536 --- /dev/null +++ b/internal/config/kubernetes/v1.1/include/cluster/wait.go @@ -0,0 +1,59 @@ +package cluster + +import ( + "context" + "net/http" + "strings" + + "github.com/SchwarzIT/community-stackit-go-client/pkg/services/kubernetes/v1.1/cluster" + "github.com/SchwarzIT/community-stackit-go-client/pkg/wait" +) + +func (*CreateOrUpdateResponse) WaitHandler(ctx context.Context, c *cluster.ClientWithResponses, projectID, clusterName string) *wait.Handler { + return wait.New(func() (res interface{}, done bool, err error) { + resp, err := c.Get(ctx, projectID, clusterName) + if err != nil { + if strings.Contains(err.Error(), http.StatusText(http.StatusForbidden)) { + return nil, false, nil + } + return nil, false, err + } + if resp.StatusCode() == http.StatusForbidden { + return nil, false, nil + } + if resp.StatusCode() == http.StatusInternalServerError { + return nil, false, nil + } + if resp.Error != nil { + return nil, false, resp.Error + } + + status := *resp.JSON200.Status.Aggregated + if status == cluster.STATE_HEALTHY || status == cluster.STATE_HIBERNATED { + return resp, true, nil + } + return resp, false, nil + }) +} + +func (*DeleteResponse) WaitHandler(ctx context.Context, c *cluster.ClientWithResponses, projectID, clusterName string) *wait.Handler { + return wait.New(func() (res interface{}, done bool, err error) { + resp, err := c.Get(ctx, projectID, clusterName) + if err != nil { + if strings.Contains(err.Error(), http.StatusText(http.StatusNotFound)) { + return nil, true, nil + } + return nil, false, err + } + if resp.StatusCode() == http.StatusInternalServerError { + return nil, false, nil + } + if resp.Error != nil { + if resp.StatusCode() == http.StatusNotFound { + return nil, true, nil + } + return nil, false, err + } + return nil, false, nil + }) +} diff --git a/internal/config/kubernetes/v1.1/include/project/common.go b/internal/config/kubernetes/v1.1/include/project/common.go new file mode 100644 index 00000000..ea1962c8 --- /dev/null +++ b/internal/config/kubernetes/v1.1/include/project/common.go @@ -0,0 +1,14 @@ +// this file is only used to prevent wait.go +// from showing errors + +package project + +import "github.com/SchwarzIT/community-stackit-go-client/pkg/services/kubernetes/v1.1/project" + +type CreateResponse struct { + project.ClientWithResponsesInterface +} + +type DeleteResponse struct { + project.ClientWithResponsesInterface +} diff --git a/internal/config/kubernetes/v1.1/include/project/wait.go b/internal/config/kubernetes/v1.1/include/project/wait.go new file mode 100644 index 00000000..d0c89714 --- /dev/null +++ b/internal/config/kubernetes/v1.1/include/project/wait.go @@ -0,0 +1,60 @@ +package project + +import ( + "context" + "fmt" + "net/http" + "strings" + + "github.com/SchwarzIT/community-stackit-go-client/pkg/services/kubernetes/v1.1/project" + "github.com/SchwarzIT/community-stackit-go-client/pkg/wait" + "github.com/pkg/errors" +) + +func (*CreateResponse) WaitHandler(ctx context.Context, c *project.ClientWithResponses, projectID string) *wait.Handler { + return wait.New(func() (res interface{}, done bool, err error) { + + resp, err := c.Get(ctx, projectID) + if err != nil { + return nil, false, errors.Wrap(err, "failed during create request preparation") + } + if resp.Error != nil { + if strings.Contains(resp.Error.Error(), "project has no assigned namespace") { + return nil, false, nil + } + return nil, false, err + } + + switch *resp.JSON200.State { + case project.STATE_FAILED: + fallthrough + case project.STATE_DELETING: + return nil, false, fmt.Errorf("received state: %s for project ID: %s", + *resp.JSON200.State, + *resp.JSON200.ProjectID, + ) + case project.STATE_CREATED: + return nil, true, nil + } + return nil, false, nil + }) +} + +func (*DeleteResponse) WaitHandler(ctx context.Context, c *project.ClientWithResponses, projectID string) *wait.Handler { + return wait.New(func() (res interface{}, done bool, err error) { + resp, err := c.Get(ctx, projectID) + if err != nil { + if strings.Contains(err.Error(), http.StatusText(http.StatusNotFound)) { + return nil, true, nil + } + return nil, false, errors.Wrap(err, "failed during delete request preparation") + } + if resp.Error != nil { + if strings.Contains(resp.Error.Error(), http.StatusText(http.StatusNotFound)) { + return nil, true, nil + } + return nil, false, err + } + return nil, false, nil + }) +} diff --git a/internal/config/kubernetes/v1.1/include/service.go b/internal/config/kubernetes/v1.1/include/service.go new file mode 100644 index 00000000..3b6b31b2 --- /dev/null +++ b/internal/config/kubernetes/v1.1/include/service.go @@ -0,0 +1,17 @@ +package kubernetes + +import ( + "github.com/SchwarzIT/community-stackit-go-client/pkg/baseurl" + "github.com/SchwarzIT/community-stackit-go-client/pkg/contracts" + kubernetes "github.com/SchwarzIT/community-stackit-go-client/pkg/services/kubernetes/v1.1" +) + +var BaseURLs = baseurl.New( + "kubernetes", + "https://ske.api.eu01.stackit.cloud/", +) + +func NewService(c contracts.BaseClientInterface) *kubernetes.ClientWithResponses { + nc, _ := kubernetes.NewClient(BaseURLs.Get(), kubernetes.WithHTTPClient(c)) + return nc +} diff --git a/internal/config/kubernetes/v1.1/kubernetes.json b/internal/config/kubernetes/v1.1/kubernetes.json new file mode 100644 index 00000000..dae41a03 --- /dev/null +++ b/internal/config/kubernetes/v1.1/kubernetes.json @@ -0,0 +1,2418 @@ +{ + "components": { + "schemas": { + "MaintenanceAutoUpdate": { + "properties": { + "kubernetesVersion": { + "title": "Flag to enable/disable auto-updates of the Kubernetes version", + "type": "boolean" + }, + "machineImageVersion": { + "title": "Flag to enable/disable auto-updates of the OS image version", + "type": "boolean" + } + }, + "type": "object" + }, + "SkeService_CreateOrUpdateCluster_request": { + "properties": { + "extensions": { + "$ref": "#/components/schemas/v1Extension" + }, + "hibernation": { + "$ref": "#/components/schemas/v1Hibernation" + }, + "kubernetes": { + "$ref": "#/components/schemas/v1Kubernetes" + }, + "maintenance": { + "$ref": "#/components/schemas/v1Maintenance" + }, + "network": { + "$ref": "#/components/schemas/v1Network" + }, + "nodepools": { + "items": { + "$ref": "#/components/schemas/v1Nodepool" + }, + "maxItems": 10, + "minItems": 1, + "type": "array" + }, + "status": { + "$ref": "#/components/schemas/v1ClusterStatus" + } + }, + "required": [ + "kubernetes", + "nodepools" + ], + "type": "object" + }, + "v1ACL": { + "properties": { + "allowedCidrs": { + "description": "Array of CIDRs to allow access to the kubernetes API.", + "items": { + "type": "string" + }, + "type": "array" + }, + "enabled": { + "description": "Enables the acl extension.", + "type": "boolean" + } + }, + "required": [ + "allowedCidrs", + "enabled" + ], + "type": "object" + }, + "v1Argus": { + "properties": { + "argusInstanceId": { + "description": "Argus instance ID to choose which Argus instance is used.", + "type": "string" + }, + "enabled": { + "description": "Enables the argus extension.", + "type": "boolean" + } + }, + "required": [ + "argusInstanceId", + "enabled" + ], + "type": "object" + }, + "v1AvailabilityZone": { + "properties": { + "name": { + "type": "string" + } + }, + "type": "object" + }, + "v1CRI": { + "properties": { + "name": { + "enum": [ + "docker", + "containerd" + ], + "title": "Name of the cri library", + "type": "string" + } + }, + "type": "object" + }, + "v1Cluster": { + "properties": { + "extensions": { + "$ref": "#/components/schemas/v1Extension" + }, + "hibernation": { + "$ref": "#/components/schemas/v1Hibernation" + }, + "kubernetes": { + "$ref": "#/components/schemas/v1Kubernetes" + }, + "maintenance": { + "$ref": "#/components/schemas/v1Maintenance" + }, + "name": { + "readOnly": true, + "type": "string" + }, + "network": { + "$ref": "#/components/schemas/v1Network" + }, + "nodepools": { + "items": { + "$ref": "#/components/schemas/v1Nodepool" + }, + "maxItems": 10, + "minItems": 1, + "type": "array" + }, + "status": { + "$ref": "#/components/schemas/v1ClusterStatus" + } + }, + "required": [ + "kubernetes", + "nodepools" + ], + "type": "object" + }, + "v1ClusterStatus": { + "properties": { + "aggregated": { + "$ref": "#/components/schemas/v1ClusterStatusState" + }, + "creationTime": { + "description": "Format: `2024-02-15T11:06:29Z`", + "title": "Cluster creation timestamp", + "type": "string" + }, + "credentialsRotation": { + "$ref": "#/components/schemas/v1CredentialsRotation" + }, + "error": { + "$ref": "#/components/schemas/v1RuntimeError" + }, + "hibernated": { + "title": "Indicates whether the cluster is currently hibernated", + "type": "boolean" + } + }, + "type": "object" + }, + "v1ClusterStatusState": { + "default": "STATE_UNSPECIFIED", + "enum": [ + "STATE_UNSPECIFIED", + "STATE_HEALTHY", + "STATE_CREATING", + "STATE_DELETING", + "STATE_UNHEALTHY", + "STATE_RECONCILING", + "STATE_HIBERNATED", + "STATE_HIBERNATING", + "STATE_WAKINGUP" + ], + "title": "aggregated state of the cluster", + "type": "string" + }, + "v1Clusters": { + "properties": { + "items": { + "items": { + "$ref": "#/components/schemas/v1Cluster" + }, + "type": "array" + } + }, + "type": "object" + }, + "v1Credentials": { + "properties": { + "certificateAuthorityData": { + "title": "Certificate authority data for accessing the cluster", + "type": "string" + }, + "kubeconfig": { + "description": "This string contains the kubeconfig as yaml.", + "title": "Kubeconfig for the cluster as yml string", + "type": "string" + }, + "server": { + "title": "Kubernetes api server address", + "type": "string" + }, + "token": { + "title": "Access token used to authenticate with the cluster", + "type": "string" + } + }, + "type": "object" + }, + "v1CredentialsRotation": { + "properties": { + "lastCompletionTime": { + "description": "Format: `2024-02-15T11:06:29Z`", + "title": "CredentialsRotation last completed at", + "type": "string" + }, + "lastInitiationTime": { + "description": "Format: `2024-02-15T11:06:29Z`", + "title": "CredentialsRotation last started at", + "type": "string" + }, + "phase": { + "description": "Phase of the credentials rotation. `NEVER` indicates that no credentials rotation has been performed using the new credentials rotation endpoints yet. Using the deprecated [rotate-credentials](#tag/Credentials/operation/SkeService_GetClusterCredentials) endpoint will not update this status field.", + "enum": [ + "NEVER", + "PREPARING", + "PREPARED", + "COMPLETING", + "COMPLETED" + ], + "type": "string" + } + }, + "type": "object" + }, + "v1Extension": { + "properties": { + "acl": { + "$ref": "#/components/schemas/v1ACL" + }, + "argus": { + "$ref": "#/components/schemas/v1Argus" + } + }, + "type": "object" + }, + "v1Hibernation": { + "properties": { + "schedules": { + "items": { + "$ref": "#/components/schemas/v1HibernationSchedule" + }, + "type": "array" + } + }, + "required": [ + "schedules" + ], + "type": "object" + }, + "v1HibernationSchedule": { + "properties": { + "end": { + "pattern": "(@(annually|yearly|monthly|weekly|daily|hourly|reboot))|(@every (\\d+(ns|us|µs|ms|s|m|h))+)|((((\\d+,)+\\d+|(\\d+(\\/|-)\\d+)|\\d+|\\*) ?){5,7})", + "title": "End time of cluster hibernation, in crontab syntax; this is the time the cluster will be woken up", + "type": "string" + }, + "start": { + "pattern": "(@(annually|yearly|monthly|weekly|daily|hourly|reboot))|(@every (\\d+(ns|us|µs|ms|s|m|h))+)|((((\\d+,)+\\d+|(\\d+(\\/|-)\\d+)|\\d+|\\*) ?){5,7})", + "title": "Start time of cluster hibernation, in crontab syntax", + "type": "string" + }, + "timezone": { + "title": "Timezone name corresponding to a file in the IANA Time Zone database (like Go's time.LoadLocation).\nAn example would be \"Europe/Berlin\"", + "type": "string" + } + }, + "required": [ + "end", + "start" + ], + "type": "object" + }, + "v1Image": { + "description": "For valid names and versions please take a look at [provider-options](#tag/ProviderOptions/operation/SkeService_GetProviderOptions) `machineImages`.", + "properties": { + "name": { + "title": "Name of os image", + "type": "string" + }, + "version": { + "title": "Version of os image", + "type": "string" + } + }, + "required": [ + "version" + ], + "type": "object" + }, + "v1Kubeconfig": { + "properties": { + "expirationTimestamp": { + "type": "string" + }, + "kubeconfig": { + "type": "string" + } + }, + "type": "object" + }, + "v1KubeconfigRequest": { + "properties": { + "expirationSeconds": { + "type": "string" + } + }, + "type": "object" + }, + "v1Kubernetes": { + "description": "For valid versions please take a look at [provider-options](#tag/ProviderOptions/operation/SkeService_GetProviderOptions) `kubernetesVersions`.", + "properties": { + "allowPrivilegedContainers": { + "description": "DEPRECATED as of Kubernetes 1.25+\nFlag to specify if privileged mode for containers is enabled or not.\nThis should be used with care since it also disables a couple of other features like the use of some volume type (e.g. PVCs).\nBy default this is set to true.", + "type": "boolean" + }, + "version": { + "pattern": "^\\d+\\.\\d+\\.\\d+$", + "title": "Kubernetes version used for the cluster", + "type": "string" + } + }, + "required": [ + "version" + ], + "type": "object" + }, + "v1KubernetesVersion": { + "properties": { + "expirationDate": { + "title": "Expiration date until the version will be supported if known yet", + "type": "string" + }, + "featureGates": { + "additionalProperties": { + "type": "string" + }, + "title": "List of feature gates supported by the Kubernetes version", + "type": "object" + }, + "state": { + "title": "State of the kubernetes version", + "type": "string" + }, + "version": { + "pattern": "^\\d+\\.\\d+\\.\\d+$", + "title": "Kubernetes version", + "type": "string" + } + }, + "type": "object" + }, + "v1Machine": { + "properties": { + "image": { + "$ref": "#/components/schemas/v1Image" + }, + "type": { + "description": "For valid types please take a look at [provider-options](#tag/ProviderOptions/operation/SkeService_GetProviderOptions) `machineTypes`.", + "type": "string" + } + }, + "required": [ + "image", + "type" + ], + "type": "object" + }, + "v1MachineImage": { + "properties": { + "name": { + "title": "Image name", + "type": "string" + }, + "versions": { + "items": { + "$ref": "#/components/schemas/v1MachineImageVersion" + }, + "type": "array" + } + }, + "type": "object" + }, + "v1MachineImageVersion": { + "properties": { + "cri": { + "items": { + "$ref": "#/components/schemas/v1CRI" + }, + "title": "supported container runtimes", + "type": "array" + }, + "expirationDate": { + "type": "string" + }, + "state": { + "type": "string" + }, + "version": { + "pattern": "^\\d+\\.\\d+\\.\\d+$", + "title": "Image version", + "type": "string" + } + }, + "type": "object" + }, + "v1MachineType": { + "properties": { + "cpu": { + "title": "number of CPU cores", + "type": "integer" + }, + "memory": { + "title": "memory in GB", + "type": "integer" + }, + "name": { + "type": "string" + } + }, + "type": "object" + }, + "v1Maintenance": { + "properties": { + "autoUpdate": { + "$ref": "#/components/schemas/MaintenanceAutoUpdate" + }, + "timeWindow": { + "$ref": "#/components/schemas/v1TimeWindow" + } + }, + "required": [ + "autoUpdate", + "timeWindow" + ], + "type": "object" + }, + "v1Network": { + "properties": { + "id": { + "title": "ID of the SNA network into which the cluster will be deployed", + "type": "string" + } + }, + "type": "object" + }, + "v1Nodepool": { + "properties": { + "availabilityZones": { + "items": { + "type": "string" + }, + "type": "array" + }, + "cri": { + "$ref": "#/components/schemas/v1CRI" + }, + "labels": { + "additionalProperties": { + "type": "string" + }, + "title": "List of labels attached to all worker nodes of this node pool", + "type": "object" + }, + "machine": { + "$ref": "#/components/schemas/v1Machine" + }, + "maxSurge": { + "maximum": 10, + "minimum": 1, + "title": "Maximum number of additional VMs that are created during an update", + "type": "integer" + }, + "maxUnavailable": { + "title": "Maximum number of VMs that that can be unavailable during an update", + "type": "integer" + }, + "maximum": { + "maximum": 100, + "minimum": 1, + "title": "Maximum number of nodes in the pool", + "type": "integer" + }, + "minimum": { + "maximum": 100, + "minimum": 1, + "title": "Minimum number of nodes in the pool", + "type": "integer" + }, + "name": { + "description": "Maximum 15 chars", + "title": "Name of the node pool", + "type": "string" + }, + "taints": { + "items": { + "$ref": "#/components/schemas/v1Taint" + }, + "title": "List of taints for all the worker nodes of this node pool", + "type": "array" + }, + "volume": { + "$ref": "#/components/schemas/v1Volume" + } + }, + "required": [ + "availabilityZones", + "machine", + "maximum", + "minimum", + "name", + "volume" + ], + "type": "object" + }, + "v1NoopFeature": { + "properties": { + "content": { + "type": "string" + } + }, + "type": "object" + }, + "v1Project": { + "properties": { + "projectId": { + "type": "string" + }, + "state": { + "$ref": "#/components/schemas/v1ProjectState" + } + }, + "type": "object" + }, + "v1ProjectState": { + "default": "STATE_UNSPECIFIED", + "enum": [ + "STATE_UNSPECIFIED", + "STATE_CREATING", + "STATE_CREATED", + "STATE_DELETING", + "STATE_FAILED" + ], + "type": "string" + }, + "v1ProviderOptions": { + "properties": { + "availabilityZones": { + "items": { + "$ref": "#/components/schemas/v1AvailabilityZone" + }, + "type": "array" + }, + "kubernetesVersions": { + "items": { + "$ref": "#/components/schemas/v1KubernetesVersion" + }, + "title": "List of supported Kubernetes versions", + "type": "array" + }, + "machineImages": { + "items": { + "$ref": "#/components/schemas/v1MachineImage" + }, + "type": "array" + }, + "machineTypes": { + "items": { + "$ref": "#/components/schemas/v1MachineType" + }, + "title": "List of supported machine types", + "type": "array" + }, + "volumeTypes": { + "items": { + "$ref": "#/components/schemas/v1VolumeType" + }, + "type": "array" + } + }, + "type": "object" + }, + "v1RuntimeError": { + "properties": { + "code": { + "description": "- Code: `SKE_UNSPECIFIED`\n Message: \"An error occurred. Please open a support ticket if this error persists.\"\n- Code: `SKE_TMP_AUTH_ERROR`\n Message: \"Authentication failed. This is a temporary error. Please wait while the system recovers.\"\n- Code: `SKE_QUOTA_EXCEEDED`\n Message: \"Your project's resource quotas are exhausted. Please make sure your quota is sufficient for the ordered cluster.\"\n- Code: `SKE_ARGUS_INSTANCE_NOT_FOUND`\n Message: \"The provided Argus instance could not be found.\"\n- Code: `SKE_RATE_LIMITS`\n Message: \"While provisioning your cluster, request rate limits where incurred. Please wait while the system recovers.\"\n- Code: `SKE_INFRA_ERROR`\n Message: \"An error occurred with the underlying infrastructure. Please open a support ticket if this error persists.\"\n- Code: `SKE_REMAINING_RESOURCES`\n Message: \"There are remaining Kubernetes resources in your cluster that prevent deletion. Please make sure to remove them.\"\n- Code: `SKE_CONFIGURATION_PROBLEM`\n Message: \"A configuration error occurred. Please open a support ticket if this error persists.\"\n- Code: `SKE_UNREADY_NODES`\n Message: \"Not all worker nodes are ready. Please open a support ticket if this error persists.\"\n- Code: `SKE_API_SERVER_ERROR`\n Message: \"The Kubernetes API server is not reporting readiness. Please open a support ticket if this error persists.\"\n", + "enum": [ + "SKE_UNSPECIFIED", + "SKE_TMP_AUTH_ERROR", + "SKE_QUOTA_EXCEEDED", + "SKE_ARGUS_INSTANCE_NOT_FOUND", + "SKE_RATE_LIMITS", + "SKE_INFRA_ERROR", + "SKE_REMAINING_RESOURCES", + "SKE_CONFIGURATION_PROBLEM", + "SKE_UNREADY_NODES", + "SKE_API_SERVER_ERROR" + ], + "type": "string" + }, + "details": { + "type": "string" + }, + "message": { + "type": "string" + } + }, + "type": "object" + }, + "v1Taint": { + "properties": { + "effect": { + "enum": [ + "NoSchedule", + "PreferNoSchedule", + "NoExecute" + ], + "type": "string" + }, + "key": { + "title": "Taint key to be applied to a node", + "type": "string" + }, + "value": { + "title": "Taint value corresponding to the taint key", + "type": "string" + } + }, + "required": [ + "effect", + "key" + ], + "type": "object" + }, + "v1TimeWindow": { + "properties": { + "end": { + "title": "Format: 0000-01-01THH:MM:SS+00:00 e.g. 0000-01-01T24:00:00+00:00", + "type": "string" + }, + "start": { + "title": "Format: 0000-01-01THH:MM:SS+00:00 e.g. 0000-01-01T23:00:00+00:00", + "type": "string" + } + }, + "required": [ + "end", + "start" + ], + "type": "object" + }, + "v1Volume": { + "properties": { + "size": { + "maximum": 10240, + "minimum": 20, + "title": "Size of volume in GB", + "type": "integer" + }, + "type": { + "description": "For valid values please take a look at [provider-options](#tag/ProviderOptions/operation/SkeService_GetProviderOptions) `volumeTypes`.", + "type": "string" + } + }, + "required": [ + "size" + ], + "type": "object" + }, + "v1VolumeType": { + "properties": { + "name": { + "type": "string" + } + }, + "type": "object" + } + }, + "securitySchemes": { + "bearerAuth": { + "bearerFormat": "JWT", + "scheme": "bearer", + "type": "http" + } + } + }, + "info": { + "contact": { + "name": "STACKIT Kubernetes Engine (SKE) Team", + "url": "https://support.stackit.cloud/servicedesk" + }, + "description": "The SKE API provides endpoints to create, update, delete clusters within STACKIT portal projects and to trigger further cluster management tasks.", + "termsOfService": "https://stackit.de/en/imprint", + "title": "SKE-API", + "version": "1.1" + }, + "openapi": "3.0.1", + "paths": { + "/v1/noop-feature": { + "get": { + "description": "This endpoint is enabled or disabled based on the `NoopFeature` gate.", + "operationId": "SkeService_GetNoopFeature", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1NoopFeature" + } + } + }, + "description": "A successful response." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "Dummy endpoint for feature gates", + "tags": [ + "NoopFeature" + ], + "x-stackit-authorization": { + "disabled": true + }, + "x-stackit-scope": { + "visibility": "hidden" + } + } + }, + "/v1/projects/{projectId}": { + "delete": { + "description": "Deletes the SKE project specified by `projectId`. Deleting a project deletes all corresponding shoots.", + "operationId": "SkeService_DeleteProject", + "parameters": [ + { + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "A successful response." + }, + "202": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Accepted. Deletion happens asynchronously." + }, + "400": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Invalid request." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "Delete a project", + "tags": [ + "Project" + ], + "x-stackit-authorization": { + "actions": [ + "project.resource.write" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project" + }, + "x-viewer-permissions": { + "actions": [ + "project.resources.edit" + ] + } + }, + "get": { + "description": "Get a Project specified by `projectId`.", + "operationId": "SkeService_GetProject", + "parameters": [ + { + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1Project" + } + } + }, + "description": "A successful response." + }, + "404": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Project not found." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "Get a Project", + "tags": [ + "Project" + ], + "x-stackit-authorization": { + "actions": [ + "project.read" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project" + }, + "x-viewer-permissions": { + "actions": [ + "project.read" + ] + } + }, + "put": { + "description": "Returns creation state of Project specified by `projectId`.", + "operationId": "SkeService_CreateProject", + "parameters": [ + { + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1Project" + } + } + }, + "description": "A successful response." + }, + "400": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Invalid request." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "Create a Project", + "tags": [ + "Project" + ], + "x-stackit-authorization": { + "actions": [ + "project.resource.write" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project" + }, + "x-viewer-permissions": { + "actions": [ + "project.resources.edit" + ] + } + } + }, + "/v1/projects/{projectId}/clusters": { + "get": { + "description": "Return a list of Kubernetes clusters in the project specified by `projectId`.", + "operationId": "SkeService_ListClusters", + "parameters": [ + { + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1Clusters" + } + } + }, + "description": "A successful response." + }, + "400": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Invalid request." + }, + "404": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Project not found." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "List all clusters", + "tags": [ + "Cluster" + ], + "x-stackit-authorization": { + "actions": [ + "project.read" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project", + "service-enablement": { + "services": [ + "cloud.stackit.ske" + ] + } + }, + "x-viewer-permissions": { + "actions": [ + "project.read" + ] + } + } + }, + "/v1/projects/{projectId}/clusters/{clusterName}": { + "delete": { + "description": "Delete Kubernetes cluster specified by the identifier, belonging to the project specified by `projectId`.", + "operationId": "SkeService_DeleteCluster", + "parameters": [ + { + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "clusterName", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "A successful response." + }, + "202": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Accepted, deletion of cluster happens asynchronously. The deletion is done as soon as GetCluster returns a 404 code. The progress can be observerd in the GetCluster's lastOperation field that contains a progress indicator." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "Delete a cluster", + "tags": [ + "Cluster" + ], + "x-stackit-authorization": { + "actions": [ + "project.resource.write" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project", + "service-enablement": { + "services": [ + "cloud.stackit.ske" + ] + } + }, + "x-viewer-permissions": { + "actions": [ + "project.resources.edit" + ] + } + }, + "get": { + "description": "Get Kubernetes cluster for the specified identifier, belonging to the project specified by `projectId`.", + "operationId": "SkeService_GetCluster", + "parameters": [ + { + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "clusterName", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1Cluster" + } + } + }, + "description": "A successful response." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "Get a cluster", + "tags": [ + "Cluster" + ], + "x-stackit-authorization": { + "actions": [ + "project.read" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project", + "service-enablement": { + "services": [ + "cloud.stackit.ske" + ] + } + }, + "x-viewer-permissions": { + "actions": [ + "project.read" + ] + } + }, + "put": { + "description": "Create a new cluster in your project or modify an existing one. To get valid values for certain properties please check the [provider-options](#tag/ProviderOptions/operation/SkeService_GetProviderOptions) endpoint.", + "operationId": "SkeService_CreateOrUpdateCluster", + "parameters": [ + { + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "clusterName", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/SkeService_CreateOrUpdateCluster_request" + } + } + }, + "required": true + }, + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1Cluster" + } + } + }, + "description": "A successful response." + }, + "202": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Accepted, creation/update of cluster happens asynchronously. The status of the cluster is specified in the status.conditions array of the response object. An entry in the status.conditions array represents the status of a condition type, whereat following types are supported: APIServerAvailable, ControlPlaneHealthy, EveryNodeReady, SystemComponentsHealthy. After creation of a cluster is triggered, the status of those types is initially `Progressing` and changes to `True` when the related type is successfully created and available." + }, + "400": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Invalid request." + }, + "404": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Project not found." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "Create or update a cluster", + "tags": [ + "Cluster" + ], + "x-codegen-request-body-name": "cluster", + "x-stackit-authorization": { + "actions": [ + "project.resource.write" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project", + "service-enablement": { + "services": [ + "cloud.stackit.ske" + ] + } + }, + "x-viewer-permissions": { + "actions": [ + "project.resources.edit" + ] + } + } + }, + "/v1/projects/{projectId}/clusters/{clusterName}/complete-credentials-rotation": { + "post": { + "description": "Complete cluster credentials rotation. This is step 2 of a two-step process. Start the rotation using [start-credentials-rotation](#tag/Credentials/operation/SkeService_StartClusterCredentialsRotation).", + "operationId": "SkeService_CompleteClusterCredentialsRotation", + "parameters": [ + { + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "clusterName", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "A successful response." + }, + "202": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Accepted, execution happens asynchronously. Use the [get cluster](#tag/Cluster/operation/SkeService_GetCluster) endpoint to get the status of the operation from `status.credentialsRotation`." + }, + "400": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Invalid request." + }, + "404": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Cluster not found." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "Complete cluster credentials rotation", + "tags": [ + "Operation", + "Credentials" + ], + "x-stackit-authorization": { + "actions": [ + "project.resource.write" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project", + "service-enablement": { + "services": [ + "cloud.stackit.ske" + ] + } + }, + "x-viewer-permissions": { + "actions": [ + "project.resources.edit" + ] + } + } + }, + "/v1/projects/{projectId}/clusters/{clusterName}/credentials": { + "get": { + "deprecated": true, + "description": "This endpoint is deprecated since 2024-01-26. It will not work for clusters with Kubernetes v1.27+, or if the new endpoints for kubeconfig or credentials rotation have already been used. Use [kubeconfig](#tag/Credentials/operation/SkeService_CreateKubeconfig) instead to obtain a kubeconfig. For more information, see [How to rotate SKE credentials](https://docs.stackit.cloud/display/STACKIT/How+to+rotate+SKE+credentials).\n\nGet credentials for the cluster specified by `clusterName`, belonging to the project specified by `projectId`.", + "operationId": "SkeService_GetClusterCredentials", + "parameters": [ + { + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "clusterName", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1Credentials" + } + } + }, + "description": "A successful response." + }, + "400": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Invalid request." + }, + "404": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Credentials were not found." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "Get credentials for a cluster", + "tags": [ + "Credentials" + ], + "x-stackit-authorization": { + "actions": [ + "project.resource.write" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project", + "service-enablement": { + "services": [ + "cloud.stackit.ske" + ] + } + }, + "x-viewer-permissions": { + "actions": [ + "project.resources.edit" + ] + } + } + }, + "/v1/projects/{projectId}/clusters/{clusterName}/hibernate": { + "post": { + "description": "Trigger immediate hibernation of the cluster. If the cluster is already in hibernation state, the method does nothing.", + "operationId": "SkeService_TriggerClusterHibernation", + "parameters": [ + { + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "clusterName", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "A successful response." + }, + "202": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Accepted, execution happens asynchronously. Use GetCluster endpoint to read the status of the cluster via status.conditions." + }, + "404": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Cluster not found." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "Trigger cluster hibernation", + "tags": [ + "Operation", + "Cluster" + ], + "x-stackit-authorization": { + "actions": [ + "project.resource.write" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project", + "service-enablement": { + "services": [ + "cloud.stackit.ske" + ] + } + }, + "x-viewer-permissions": { + "actions": [ + "project.resources.edit" + ] + } + } + }, + "/v1/projects/{projectId}/clusters/{clusterName}/kubeconfig": { + "post": { + "description": "Create a new kubeconfig for the cluster. You can specify the expiration (in seconds) in the request body. Its value must be in the range from 3600 (1 hour) to 15552000 (6 months).", + "operationId": "SkeService_CreateKubeconfig", + "parameters": [ + { + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "clusterName", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1KubeconfigRequest" + } + } + }, + "required": true + }, + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1Kubeconfig" + } + } + }, + "description": "A successful response." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "Create a kubeconfig", + "tags": [ + "Operation", + "Credentials" + ], + "x-codegen-request-body-name": "kubeconfigRequest", + "x-stackit-authorization": { + "actions": [ + "project.resource.write" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project", + "service-enablement": { + "services": [ + "cloud.stackit.ske" + ] + } + }, + "x-viewer-permissions": { + "actions": [ + "project.resources.edit" + ] + } + } + }, + "/v1/projects/{projectId}/clusters/{clusterName}/maintenance": { + "post": { + "description": "Trigger immediate maintenance of the cluster. The autoUpdate configuration specified in the Maintenance object of the cluster spec defines what is updated during the immediate maintenance operation.", + "operationId": "SkeService_TriggerClusterMaintenance", + "parameters": [ + { + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "clusterName", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "A successful response." + }, + "202": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Accepted, execution happens asynchronously. Use GetCluster endpoint to read the status of the cluster via status.conditions." + }, + "404": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Cluster not found." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "Trigger cluster maintenance", + "tags": [ + "Operation", + "Cluster" + ], + "x-stackit-authorization": { + "actions": [ + "project.resource.write" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project", + "service-enablement": { + "services": [ + "cloud.stackit.ske" + ] + } + }, + "x-viewer-permissions": { + "actions": [ + "project.resources.edit" + ] + } + } + }, + "/v1/projects/{projectId}/clusters/{clusterName}/reconcile": { + "post": { + "description": "Trigger immediate reconciliation of the complete cluster without changing the cluster specification.", + "operationId": "SkeService_TriggerClusterReconciliation", + "parameters": [ + { + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "clusterName", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "A successful response." + }, + "202": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Accepted, execution happens asynchronously. Use GetCluster endpoint to read the status of the cluster via status.conditions." + }, + "404": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Cluster not found." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "Trigger cluster reconciliation", + "tags": [ + "Operation", + "Cluster" + ], + "x-stackit-authorization": { + "actions": [ + "project.resource.write" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project", + "service-enablement": { + "services": [ + "cloud.stackit.ske" + ] + } + }, + "x-viewer-permissions": { + "actions": [ + "project.resources.edit" + ] + } + } + }, + "/v1/projects/{projectId}/clusters/{clusterName}/rotate-credentials": { + "post": { + "deprecated": true, + "description": "This endpoint is deprecated since 2024-01-26. It will not work for clusters with Kubernetes v1.27+, or if the new endpoints for kubeconfig or credentials rotation have already been used. Use [start-credentials-rotation](#tag/Credentials/operation/SkeService_StartClusterCredentialsRotation) instead to rotate all cluster credentials. For more information, see [How to rotate SKE credentials](https://docs.stackit.cloud/display/STACKIT/How+to+rotate+SKE+credentials).\n\nTrigger credential rotation. The old credentials (kubeconfig) will be invalid after the operation.", + "operationId": "SkeService_TriggerClusterCredentialRotation", + "parameters": [ + { + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "clusterName", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "A successful response." + }, + "202": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Accepted, execution happens asynchronously. Use GetCluster endpoint to read the status of the cluster via status.conditions." + }, + "404": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Cluster not found." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "Rotate cluster credentials", + "tags": [ + "Operation", + "Credentials" + ], + "x-stackit-authorization": { + "actions": [ + "project.resource.write" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project", + "service-enablement": { + "services": [ + "cloud.stackit.ske" + ] + } + }, + "x-viewer-permissions": { + "actions": [ + "project.resources.edit" + ] + } + } + }, + "/v1/projects/{projectId}/clusters/{clusterName}/start-credentials-rotation": { + "post": { + "description": "Start cluster credentials rotation. This is step 1 of a two-step process. Complete the rotation using [complete-credentials-rotation](#tag/Credentials/operation/SkeService_CompleteClusterCredentialsRotation).", + "operationId": "SkeService_StartClusterCredentialsRotation", + "parameters": [ + { + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "clusterName", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "A successful response." + }, + "202": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Accepted, execution happens asynchronously. Use the [get cluster](#tag/Cluster/operation/SkeService_GetCluster) endpoint to get the status of the operation from `status.credentialsRotation`." + }, + "400": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Invalid request." + }, + "404": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Cluster not found." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "Start cluster credentials rotation", + "tags": [ + "Operation", + "Credentials" + ], + "x-stackit-authorization": { + "actions": [ + "project.resource.write" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project", + "service-enablement": { + "services": [ + "cloud.stackit.ske" + ] + } + }, + "x-viewer-permissions": { + "actions": [ + "project.resources.edit" + ] + } + } + }, + "/v1/projects/{projectId}/clusters/{clusterName}/wakeup": { + "post": { + "description": "Trigger immediate wake up of the cluster. If the cluster is already in running state, the method does nothing.", + "operationId": "SkeService_TriggerClusterWakeup", + "parameters": [ + { + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "clusterName", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "A successful response." + }, + "202": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Accepted, execution happens asynchronously. Use GetCluster endpoint to read the status of the cluster via status.conditions." + }, + "404": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Cluster not found." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "Trigger cluster wakeup", + "tags": [ + "Operation", + "Cluster" + ], + "x-stackit-authorization": { + "actions": [ + "project.resource.write" + ], + "resource-id": "projectId", + "resource-id-type": "dynamic", + "resource-type": "project", + "service-enablement": { + "services": [ + "cloud.stackit.ske" + ] + } + }, + "x-viewer-permissions": { + "actions": [ + "project.resources.edit" + ] + } + } + }, + "/v1/provider-options": { + "get": { + "description": "Returns a list of supported Kubernetes versions and a list of supported machine types for the cluster nodes.", + "operationId": "SkeService_GetProviderOptions", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1ProviderOptions" + } + } + }, + "description": "A successful response." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "List provider options", + "tags": [ + "ProviderOptions" + ], + "x-stackit-authorization": { + "disabled": true + } + } + }, + "/v1/system/projects/{projectId}": { + "delete": { + "description": "System endpoint for /v1/projects/{projectId}", + "operationId": "SkeService_System_DeleteProject", + "parameters": [ + { + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "A successful response." + }, + "202": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Accepted. Deletion happens asynchronously." + }, + "400": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Invalid request." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "Delete a project (With system permissions)", + "tags": [ + "System" + ], + "x-stackit-authorization": { + "actions": [ + "system.ske.delete" + ], + "resource-id": "system", + "resource-id-type": "static", + "resource-type": "system" + }, + "x-stackit-scope": { + "visibility": "private" + }, + "x-stackit-upstream": { + "path": "/v1/projects/{projectId}" + }, + "x-viewer-permissions": { + "actions": [ + "system.ske.delete" + ] + } + }, + "get": { + "description": "System endpoint for /v1/projects/{projectId}", + "operationId": "SkeService_System_GetProject", + "parameters": [ + { + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1Project" + } + } + }, + "description": "A successful response." + }, + "404": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Project not found." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "Get a Project (With system permissions)", + "tags": [ + "System" + ], + "x-stackit-authorization": { + "actions": [ + "system.ske.delete" + ], + "resource-id": "system", + "resource-id-type": "static", + "resource-type": "system" + }, + "x-stackit-scope": { + "visibility": "private" + }, + "x-stackit-upstream": { + "path": "/v1/projects/{projectId}" + }, + "x-viewer-permissions": { + "actions": [ + "system.ske.delete" + ] + } + } + }, + "/v1/system/projects/{projectId}/clusters/{clusterName}/reconcile": { + "post": { + "description": "System endpoint for /v1/projects/{projectId}/clusters/{clusterName}/reconcile", + "operationId": "SkeService_System_TriggerClusterReconciliation", + "parameters": [ + { + "in": "path", + "name": "projectId", + "required": true, + "schema": { + "type": "string" + } + }, + { + "in": "path", + "name": "clusterName", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "A successful response." + }, + "202": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Accepted, execution happens asynchronously." + }, + "404": { + "content": { + "application/json": { + "schema": { + "type": "object" + } + } + }, + "description": "Cluster not found." + }, + "default": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/v1RuntimeError" + } + } + }, + "description": "An unexpected error response." + } + }, + "summary": "Trigger cluster reconciliation (With system permissions)", + "tags": [ + "System" + ], + "x-stackit-authorization": { + "actions": [ + "system.ske.reconcile" + ], + "resource-id": "system", + "resource-id-type": "static", + "resource-type": "system" + }, + "x-stackit-scope": { + "visibility": "private" + }, + "x-stackit-upstream": { + "path": "/v1/projects/{projectId}/clusters/{clusterName}/reconcile" + }, + "x-viewer-permissions": { + "actions": [ + "system.ske.reconcile" + ] + } + } + } + }, + "security": [ + { + "bearerAuth": [] + } + ], + "servers": [ + { + "description": "The SKE API provides endpoints to create, update, delete clusters within STACKIT", + "url": "https://ske.api.eu01.stackit.cloud" + } + ], + "tags": [ + { + "description": "Cluster related actions", + "name": "Cluster" + }, + { + "description": "Endpoints for credentials. See [How to rotate SKE credentials](https://docs.stackit.cloud/display/STACKIT/How+to+rotate+SKE+credentials) for details.", + "name": "Credentials" + }, + { + "description": "Cluster operations", + "name": "Operation" + }, + { + "description": "Endpoints for provider-options", + "name": "ProviderOptions" + }, + { + "description": "Project related actions", + "name": "Project" + } + ], + "x-original-swagger-version": "2.0", + "x-stackit-api": { + "type": "stackit" + }, + "x-stackit-scope": { + "visibility": "public" + } +} \ No newline at end of file diff --git a/pkg/services/kubernetes/v1.1/cluster/cluster.go b/pkg/services/kubernetes/v1.1/cluster/cluster.go new file mode 100644 index 00000000..c26a27ee --- /dev/null +++ b/pkg/services/kubernetes/v1.1/cluster/cluster.go @@ -0,0 +1,1517 @@ +// Package cluster provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/do87/stackit-client-generator version v0.0.2 DO NOT EDIT. +package cluster + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "strings" + + "github.com/pkg/errors" + + contracts "github.com/SchwarzIT/community-stackit-go-client/pkg/contracts" + "github.com/SchwarzIT/community-stackit-go-client/pkg/helpers/runtime" + "github.com/SchwarzIT/community-stackit-go-client/pkg/validate" +) + +const ( + BearerAuthScopes = "bearerAuth.Scopes" +) + +// Defines values for CRIName. +const ( + CONTAINERD CRIName = "containerd" + DOCKER CRIName = "docker" +) + +// Defines values for ClusterStatusState. +const ( + STATE_CREATING ClusterStatusState = "STATE_CREATING" + STATE_DELETING ClusterStatusState = "STATE_DELETING" + STATE_HEALTHY ClusterStatusState = "STATE_HEALTHY" + STATE_HIBERNATED ClusterStatusState = "STATE_HIBERNATED" + STATE_HIBERNATING ClusterStatusState = "STATE_HIBERNATING" + STATE_RECONCILING ClusterStatusState = "STATE_RECONCILING" + STATE_UNHEALTHY ClusterStatusState = "STATE_UNHEALTHY" + STATE_UNSPECIFIED ClusterStatusState = "STATE_UNSPECIFIED" + STATE_WAKINGUP ClusterStatusState = "STATE_WAKINGUP" +) + +// Defines values for CredentialsRotationPhase. +const ( + COMPLETED CredentialsRotationPhase = "COMPLETED" + COMPLETING CredentialsRotationPhase = "COMPLETING" + NEVER CredentialsRotationPhase = "NEVER" + PREPARED CredentialsRotationPhase = "PREPARED" + PREPARING CredentialsRotationPhase = "PREPARING" +) + +// Defines values for RuntimeErrorCode. +const ( + SKE_API_SERVER_ERROR RuntimeErrorCode = "SKE_API_SERVER_ERROR" + SKE_ARGUS_INSTANCE_NOT_FOUND RuntimeErrorCode = "SKE_ARGUS_INSTANCE_NOT_FOUND" + SKE_CONFIGURATION_PROBLEM RuntimeErrorCode = "SKE_CONFIGURATION_PROBLEM" + SKE_INFRA_ERROR RuntimeErrorCode = "SKE_INFRA_ERROR" + SKE_QUOTA_EXCEEDED RuntimeErrorCode = "SKE_QUOTA_EXCEEDED" + SKE_RATE_LIMITS RuntimeErrorCode = "SKE_RATE_LIMITS" + SKE_REMAINING_RESOURCES RuntimeErrorCode = "SKE_REMAINING_RESOURCES" + SKE_TMP_AUTH_ERROR RuntimeErrorCode = "SKE_TMP_AUTH_ERROR" + SKE_UNREADY_NODES RuntimeErrorCode = "SKE_UNREADY_NODES" + SKE_UNSPECIFIED RuntimeErrorCode = "SKE_UNSPECIFIED" +) + +// Defines values for TaintEffect. +const ( + NO_EXECUTE TaintEffect = "NoExecute" + NO_SCHEDULE TaintEffect = "NoSchedule" + PREFER_NO_SCHEDULE TaintEffect = "PreferNoSchedule" +) + +// ACL defines model for ACL. +type ACL struct { + // AllowedCidrs Array of CIDRs to allow access to the kubernetes API. + AllowedCidrs []string `json:"allowedCidrs"` + + // Enabled Enables the acl extension. + Enabled bool `json:"enabled"` +} + +// Argus defines model for Argus. +type Argus struct { + // ArgusInstanceId Argus instance ID to choose which Argus instance is used. + ArgusInstanceID string `json:"argusInstanceId"` + + // Enabled Enables the argus extension. + Enabled bool `json:"enabled"` +} + +// CRI defines model for CRI. +type CRI struct { + Name *CRIName `json:"name,omitempty"` +} + +// CRIName defines model for CRI.Name. +type CRIName string + +// Cluster defines model for Cluster. +type Cluster struct { + Extensions *Extension `json:"extensions,omitempty"` + Hibernation *Hibernation `json:"hibernation,omitempty"` + + // Kubernetes For valid versions please take a look at [provider-options](#tag/ProviderOptions/operation/SkeService_GetProviderOptions) `kubernetesVersions`. + Kubernetes Kubernetes `json:"kubernetes"` + Maintenance *Maintenance `json:"maintenance,omitempty"` + Name *string `json:"name,omitempty"` + Network *Network `json:"network,omitempty"` + Nodepools []Nodepool `json:"nodepools"` + Status *ClusterStatus `json:"status,omitempty"` +} + +// ClusterStatus defines model for ClusterStatus. +type ClusterStatus struct { + Aggregated *ClusterStatusState `json:"aggregated,omitempty"` + + // CreationTime Format: `2024-02-15T11:06:29Z` + CreationTime *string `json:"creationTime,omitempty"` + CredentialsRotation *CredentialsRotation `json:"credentialsRotation,omitempty"` + Error *RuntimeError `json:"error,omitempty"` + Hibernated *bool `json:"hibernated,omitempty"` +} + +// ClusterStatusState defines model for ClusterStatusState. +type ClusterStatusState string + +// Clusters defines model for Clusters. +type Clusters struct { + Items *[]Cluster `json:"items,omitempty"` +} + +// CredentialsRotation defines model for CredentialsRotation. +type CredentialsRotation struct { + // LastCompletionTime Format: `2024-02-15T11:06:29Z` + LastCompletionTime *string `json:"lastCompletionTime,omitempty"` + + // LastInitiationTime Format: `2024-02-15T11:06:29Z` + LastInitiationTime *string `json:"lastInitiationTime,omitempty"` + + // Phase Phase of the credentials rotation. `NEVER` indicates that no credentials rotation has been performed using the new credentials rotation endpoints yet. Using the deprecated [rotate-credentials](#tag/Credentials/operation/SkeService_GetClusterCredentials) endpoint will not update this status field. + Phase *CredentialsRotationPhase `json:"phase,omitempty"` +} + +// CredentialsRotationPhase Phase of the credentials rotation. `NEVER` indicates that no credentials rotation has been performed using the new credentials rotation endpoints yet. Using the deprecated [rotate-credentials](#tag/Credentials/operation/SkeService_GetClusterCredentials) endpoint will not update this status field. +type CredentialsRotationPhase string + +// Extension defines model for Extension. +type Extension struct { + Acl *ACL `json:"acl,omitempty"` + Argus *Argus `json:"argus,omitempty"` +} + +// Hibernation defines model for Hibernation. +type Hibernation struct { + Schedules []HibernationSchedule `json:"schedules"` +} + +// HibernationSchedule defines model for HibernationSchedule. +type HibernationSchedule struct { + End string `json:"end"` + Start string `json:"start"` + Timezone *string `json:"timezone,omitempty"` +} + +// Image For valid names and versions please take a look at [provider-options](#tag/ProviderOptions/operation/SkeService_GetProviderOptions) `machineImages`. +type Image struct { + Name *string `json:"name,omitempty"` + Version string `json:"version"` +} + +// Kubernetes For valid versions please take a look at [provider-options](#tag/ProviderOptions/operation/SkeService_GetProviderOptions) `kubernetesVersions`. +type Kubernetes struct { + // AllowPrivilegedContainers DEPRECATED as of Kubernetes 1.25+ + // Flag to specify if privileged mode for containers is enabled or not. + // This should be used with care since it also disables a couple of other features like the use of some volume type (e.g. PVCs). + // By default this is set to true. + AllowPrivilegedContainers *bool `json:"allowPrivilegedContainers,omitempty"` + Version string `json:"version"` +} + +// Machine defines model for Machine. +type Machine struct { + // Image For valid names and versions please take a look at [provider-options](#tag/ProviderOptions/operation/SkeService_GetProviderOptions) `machineImages`. + Image Image `json:"image"` + + // Type For valid types please take a look at [provider-options](#tag/ProviderOptions/operation/SkeService_GetProviderOptions) `machineTypes`. + Type string `json:"type"` +} + +// Maintenance defines model for Maintenance. +type Maintenance struct { + AutoUpdate MaintenanceAutoUpdate `json:"autoUpdate"` + TimeWindow TimeWindow `json:"timeWindow"` +} + +// MaintenanceAutoUpdate defines model for MaintenanceAutoUpdate. +type MaintenanceAutoUpdate struct { + KubernetesVersion *bool `json:"kubernetesVersion,omitempty"` + MachineImageVersion *bool `json:"machineImageVersion,omitempty"` +} + +// Network defines model for Network. +type Network struct { + ID *string `json:"id,omitempty"` +} + +// Nodepool defines model for Nodepool. +type Nodepool struct { + AvailabilityZones []string `json:"availabilityZones"` + CRI *CRI `json:"cri,omitempty"` + Labels *map[string]string `json:"labels,omitempty"` + Machine Machine `json:"machine"` + MaxSurge *int `json:"maxSurge,omitempty"` + MaxUnavailable *int `json:"maxUnavailable,omitempty"` + Maximum int `json:"maximum"` + Minimum int `json:"minimum"` + + // Name Maximum 15 chars + Name string `json:"name"` + Taints *[]Taint `json:"taints,omitempty"` + Volume Volume `json:"volume"` +} + +// RuntimeError defines model for RuntimeError. +type RuntimeError struct { + // Code - Code: `SKE_UNSPECIFIED` + // Message: "An error occurred. Please open a support ticket if this error persists." + // - Code: `SKE_TMP_AUTH_ERROR` + // Message: "Authentication failed. This is a temporary error. Please wait while the system recovers." + // - Code: `SKE_QUOTA_EXCEEDED` + // Message: "Your project's resource quotas are exhausted. Please make sure your quota is sufficient for the ordered cluster." + // - Code: `SKE_ARGUS_INSTANCE_NOT_FOUND` + // Message: "The provided Argus instance could not be found." + // - Code: `SKE_RATE_LIMITS` + // Message: "While provisioning your cluster, request rate limits where incurred. Please wait while the system recovers." + // - Code: `SKE_INFRA_ERROR` + // Message: "An error occurred with the underlying infrastructure. Please open a support ticket if this error persists." + // - Code: `SKE_REMAINING_RESOURCES` + // Message: "There are remaining Kubernetes resources in your cluster that prevent deletion. Please make sure to remove them." + // - Code: `SKE_CONFIGURATION_PROBLEM` + // Message: "A configuration error occurred. Please open a support ticket if this error persists." + // - Code: `SKE_UNREADY_NODES` + // Message: "Not all worker nodes are ready. Please open a support ticket if this error persists." + // - Code: `SKE_API_SERVER_ERROR` + // Message: "The Kubernetes API server is not reporting readiness. Please open a support ticket if this error persists." + Code *RuntimeErrorCode `json:"code,omitempty"` + Details *string `json:"details,omitempty"` + Message *string `json:"message,omitempty"` +} + +// RuntimeErrorCode - Code: `SKE_UNSPECIFIED` +// +// Message: "An error occurred. Please open a support ticket if this error persists." +// - Code: `SKE_TMP_AUTH_ERROR` +// Message: "Authentication failed. This is a temporary error. Please wait while the system recovers." +// - Code: `SKE_QUOTA_EXCEEDED` +// Message: "Your project's resource quotas are exhausted. Please make sure your quota is sufficient for the ordered cluster." +// - Code: `SKE_ARGUS_INSTANCE_NOT_FOUND` +// Message: "The provided Argus instance could not be found." +// - Code: `SKE_RATE_LIMITS` +// Message: "While provisioning your cluster, request rate limits where incurred. Please wait while the system recovers." +// - Code: `SKE_INFRA_ERROR` +// Message: "An error occurred with the underlying infrastructure. Please open a support ticket if this error persists." +// - Code: `SKE_REMAINING_RESOURCES` +// Message: "There are remaining Kubernetes resources in your cluster that prevent deletion. Please make sure to remove them." +// - Code: `SKE_CONFIGURATION_PROBLEM` +// Message: "A configuration error occurred. Please open a support ticket if this error persists." +// - Code: `SKE_UNREADY_NODES` +// Message: "Not all worker nodes are ready. Please open a support ticket if this error persists." +// - Code: `SKE_API_SERVER_ERROR` +// Message: "The Kubernetes API server is not reporting readiness. Please open a support ticket if this error persists." +type RuntimeErrorCode string + +// SkeServiceCreateOrUpdateClusterRequest defines model for SkeService_CreateOrUpdateCluster_request. +type SkeServiceCreateOrUpdateClusterRequest struct { + Extensions *Extension `json:"extensions,omitempty"` + Hibernation *Hibernation `json:"hibernation,omitempty"` + + // Kubernetes For valid versions please take a look at [provider-options](#tag/ProviderOptions/operation/SkeService_GetProviderOptions) `kubernetesVersions`. + Kubernetes Kubernetes `json:"kubernetes"` + Maintenance *Maintenance `json:"maintenance,omitempty"` + Network *Network `json:"network,omitempty"` + Nodepools []Nodepool `json:"nodepools"` + Status *ClusterStatus `json:"status,omitempty"` +} + +// Taint defines model for Taint. +type Taint struct { + Effect TaintEffect `json:"effect"` + Key string `json:"key"` + Value *string `json:"value,omitempty"` +} + +// TaintEffect defines model for Taint.Effect. +type TaintEffect string + +// TimeWindow defines model for TimeWindow. +type TimeWindow struct { + End string `json:"end"` + Start string `json:"start"` +} + +// Volume defines model for Volume. +type Volume struct { + Size int `json:"size"` + + // Type For valid values please take a look at [provider-options](#tag/ProviderOptions/operation/SkeService_GetProviderOptions) `volumeTypes`. + Type *string `json:"type,omitempty"` +} + +// CreateOrUpdateJSONRequestBody defines body for CreateOrUpdate for application/json ContentType. +type CreateOrUpdateJSONRequestBody = SkeServiceCreateOrUpdateClusterRequest + +// RequestEditorFn is the function signature for the RequestEditor callback function +type RequestEditorFn func(ctx context.Context, req *http.Request) error + +// Client which conforms to the OpenAPI3 specification for this service. +type Client struct { + // The endpoint of the server conforming to this interface, with scheme, + // https://api.deepmap.com for example. This can contain a path relative + // to the server, such as https://api.deepmap.com/dev-test, and all the + // paths in the swagger spec will be appended to the server. + Server string + + // Doer for performing requests, typically a *http.Client with any + // customized settings, such as certificate chains. + Client contracts.BaseClientInterface +} + +// NewRawClient Creates a new Client, with reasonable defaults +func NewRawClient(server string, httpClient contracts.BaseClientInterface) *Client { + // create a client with sane default values + client := Client{ + Server: server, + Client: httpClient, + } + return &client +} + +// The interface specification for the client above. +type rawClientInterface interface { + // List request + ListRaw(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // Delete request + DeleteRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // Get request + GetRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // CreateOrUpdate request with any body + CreateOrUpdateRawWithBody(ctx context.Context, projectID string, clusterName string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + CreateOrUpdateRaw(ctx context.Context, projectID string, clusterName string, body CreateOrUpdateJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // TriggerHibernation request + TriggerHibernationRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // TriggerMaintenance request + TriggerMaintenanceRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // TriggerReconciliation request + TriggerReconciliationRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // TriggerWakeup request + TriggerWakeupRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) +} + +func (c *Client) ListRaw(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewListRequest(ctx, c.Server, projectID) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) DeleteRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewDeleteRequest(ctx, c.Server, projectID, clusterName) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetRequest(ctx, c.Server, projectID, clusterName) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) CreateOrUpdateRawWithBody(ctx context.Context, projectID string, clusterName string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateOrUpdateRequestWithBody(ctx, c.Server, projectID, clusterName, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) CreateOrUpdateRaw(ctx context.Context, projectID string, clusterName string, body CreateOrUpdateJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateOrUpdateRequest(ctx, c.Server, projectID, clusterName, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) TriggerHibernationRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewTriggerHibernationRequest(ctx, c.Server, projectID, clusterName) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) TriggerMaintenanceRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewTriggerMaintenanceRequest(ctx, c.Server, projectID, clusterName) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) TriggerReconciliationRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewTriggerReconciliationRequest(ctx, c.Server, projectID, clusterName) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) TriggerWakeupRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewTriggerWakeupRequest(ctx, c.Server, projectID, clusterName) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +// NewListRequest generates requests for List +func NewListRequest(ctx context.Context, server string, projectID string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewDeleteRequest generates requests for Delete +func NewDeleteRequest(ctx context.Context, server string, projectID string, clusterName string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "clusterName", runtime.ParamLocationPath, clusterName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters/%s", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewGetRequest generates requests for Get +func NewGetRequest(ctx context.Context, server string, projectID string, clusterName string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "clusterName", runtime.ParamLocationPath, clusterName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters/%s", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewCreateOrUpdateRequest calls the generic CreateOrUpdate builder with application/json body +func NewCreateOrUpdateRequest(ctx context.Context, server string, projectID string, clusterName string, body CreateOrUpdateJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewCreateOrUpdateRequestWithBody(ctx, server, projectID, clusterName, "application/json", bodyReader) +} + +// NewCreateOrUpdateRequestWithBody generates requests for CreateOrUpdate with any type of body +func NewCreateOrUpdateRequestWithBody(ctx context.Context, server string, projectID string, clusterName string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "clusterName", runtime.ParamLocationPath, clusterName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters/%s", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "PUT", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewTriggerHibernationRequest generates requests for TriggerHibernation +func NewTriggerHibernationRequest(ctx context.Context, server string, projectID string, clusterName string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "clusterName", runtime.ParamLocationPath, clusterName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters/%s/hibernate", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "POST", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewTriggerMaintenanceRequest generates requests for TriggerMaintenance +func NewTriggerMaintenanceRequest(ctx context.Context, server string, projectID string, clusterName string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "clusterName", runtime.ParamLocationPath, clusterName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters/%s/maintenance", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "POST", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewTriggerReconciliationRequest generates requests for TriggerReconciliation +func NewTriggerReconciliationRequest(ctx context.Context, server string, projectID string, clusterName string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "clusterName", runtime.ParamLocationPath, clusterName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters/%s/reconcile", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "POST", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewTriggerWakeupRequest generates requests for TriggerWakeup +func NewTriggerWakeupRequest(ctx context.Context, server string, projectID string, clusterName string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "clusterName", runtime.ParamLocationPath, clusterName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters/%s/wakeup", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "POST", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { + for _, r := range additionalEditors { + if err := r(ctx, req); err != nil { + return err + } + } + return nil +} + +// ClientWithResponses builds on rawClientInterface to offer response payloads +type ClientWithResponses struct { + rawClientInterface +} + +// NewClient creates a new ClientWithResponses, which wraps +// Client with return type handling +func NewClient(server string, httpClient contracts.BaseClientInterface) *ClientWithResponses { + return &ClientWithResponses{NewRawClient(server, httpClient)} +} + +// ClientWithResponsesInterface is the interface specification for the client with responses above. +type ClientWithResponsesInterface interface { + // List request + List(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*ListResponse, error) + + // Delete request + Delete(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*DeleteResponse, error) + + // Get request + Get(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*GetResponse, error) + + // CreateOrUpdate request with any body + CreateOrUpdateWithBody(ctx context.Context, projectID string, clusterName string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateOrUpdateResponse, error) + + CreateOrUpdate(ctx context.Context, projectID string, clusterName string, body CreateOrUpdateJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateOrUpdateResponse, error) + + // TriggerHibernation request + TriggerHibernation(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*TriggerHibernationResponse, error) + + // TriggerMaintenance request + TriggerMaintenance(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*TriggerMaintenanceResponse, error) + + // TriggerReconciliation request + TriggerReconciliation(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*TriggerReconciliationResponse, error) + + // TriggerWakeup request + TriggerWakeup(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*TriggerWakeupResponse, error) +} + +type ListResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Clusters + JSON400 *map[string]interface{} + JSON404 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r ListResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r ListResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type DeleteResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *map[string]interface{} + JSON202 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r DeleteResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r DeleteResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Cluster + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r GetResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type CreateOrUpdateResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Cluster + JSON202 *map[string]interface{} + JSON400 *map[string]interface{} + JSON404 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r CreateOrUpdateResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r CreateOrUpdateResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type TriggerHibernationResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *map[string]interface{} + JSON202 *map[string]interface{} + JSON404 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r TriggerHibernationResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r TriggerHibernationResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type TriggerMaintenanceResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *map[string]interface{} + JSON202 *map[string]interface{} + JSON404 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r TriggerMaintenanceResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r TriggerMaintenanceResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type TriggerReconciliationResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *map[string]interface{} + JSON202 *map[string]interface{} + JSON404 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r TriggerReconciliationResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r TriggerReconciliationResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type TriggerWakeupResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *map[string]interface{} + JSON202 *map[string]interface{} + JSON404 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r TriggerWakeupResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r TriggerWakeupResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// List request returning *ListResponse +func (c *ClientWithResponses) List(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*ListResponse, error) { + rsp, err := c.ListRaw(ctx, projectID, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseListResponse(rsp) +} + +// Delete request returning *DeleteResponse +func (c *ClientWithResponses) Delete(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*DeleteResponse, error) { + rsp, err := c.DeleteRaw(ctx, projectID, clusterName, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseDeleteResponse(rsp) +} + +// Get request returning *GetResponse +func (c *ClientWithResponses) Get(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*GetResponse, error) { + rsp, err := c.GetRaw(ctx, projectID, clusterName, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseGetResponse(rsp) +} + +// CreateOrUpdateWithBody request with arbitrary body returning *CreateOrUpdateResponse +func (c *ClientWithResponses) CreateOrUpdateWithBody(ctx context.Context, projectID string, clusterName string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateOrUpdateResponse, error) { + rsp, err := c.CreateOrUpdateRawWithBody(ctx, projectID, clusterName, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseCreateOrUpdateResponse(rsp) +} + +func (c *ClientWithResponses) CreateOrUpdate(ctx context.Context, projectID string, clusterName string, body CreateOrUpdateJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateOrUpdateResponse, error) { + rsp, err := c.CreateOrUpdateRaw(ctx, projectID, clusterName, body, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseCreateOrUpdateResponse(rsp) +} + +// TriggerHibernation request returning *TriggerHibernationResponse +func (c *ClientWithResponses) TriggerHibernation(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*TriggerHibernationResponse, error) { + rsp, err := c.TriggerHibernationRaw(ctx, projectID, clusterName, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseTriggerHibernationResponse(rsp) +} + +// TriggerMaintenance request returning *TriggerMaintenanceResponse +func (c *ClientWithResponses) TriggerMaintenance(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*TriggerMaintenanceResponse, error) { + rsp, err := c.TriggerMaintenanceRaw(ctx, projectID, clusterName, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseTriggerMaintenanceResponse(rsp) +} + +// TriggerReconciliation request returning *TriggerReconciliationResponse +func (c *ClientWithResponses) TriggerReconciliation(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*TriggerReconciliationResponse, error) { + rsp, err := c.TriggerReconciliationRaw(ctx, projectID, clusterName, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseTriggerReconciliationResponse(rsp) +} + +// TriggerWakeup request returning *TriggerWakeupResponse +func (c *ClientWithResponses) TriggerWakeup(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*TriggerWakeupResponse, error) { + rsp, err := c.TriggerWakeupRaw(ctx, projectID, clusterName, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseTriggerWakeupResponse(rsp) +} + +// ParseListResponse parses an HTTP response from a List call +func (c *ClientWithResponses) ParseListResponse(rsp *http.Response) (*ListResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &ListResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Clusters + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseDeleteResponse parses an HTTP response from a Delete call +func (c *ClientWithResponses) ParseDeleteResponse(rsp *http.Response) (*DeleteResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &DeleteResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 202: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON202 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseGetResponse parses an HTTP response from a Get call +func (c *ClientWithResponses) ParseGetResponse(rsp *http.Response) (*GetResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Cluster + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseCreateOrUpdateResponse parses an HTTP response from a CreateOrUpdate call +func (c *ClientWithResponses) ParseCreateOrUpdateResponse(rsp *http.Response) (*CreateOrUpdateResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &CreateOrUpdateResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Cluster + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 202: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON202 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseTriggerHibernationResponse parses an HTTP response from a TriggerHibernation call +func (c *ClientWithResponses) ParseTriggerHibernationResponse(rsp *http.Response) (*TriggerHibernationResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &TriggerHibernationResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 202: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON202 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseTriggerMaintenanceResponse parses an HTTP response from a TriggerMaintenance call +func (c *ClientWithResponses) ParseTriggerMaintenanceResponse(rsp *http.Response) (*TriggerMaintenanceResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &TriggerMaintenanceResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 202: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON202 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseTriggerReconciliationResponse parses an HTTP response from a TriggerReconciliation call +func (c *ClientWithResponses) ParseTriggerReconciliationResponse(rsp *http.Response) (*TriggerReconciliationResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &TriggerReconciliationResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 202: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON202 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseTriggerWakeupResponse parses an HTTP response from a TriggerWakeup call +func (c *ClientWithResponses) ParseTriggerWakeupResponse(rsp *http.Response) (*TriggerWakeupResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &TriggerWakeupResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 202: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON202 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} diff --git a/pkg/services/kubernetes/v1.1/cluster/validate.go b/pkg/services/kubernetes/v1.1/cluster/validate.go new file mode 100644 index 00000000..f6ebec21 --- /dev/null +++ b/pkg/services/kubernetes/v1.1/cluster/validate.go @@ -0,0 +1,186 @@ +// this file is used for validating cluster data and properties + +package cluster + +import ( + "errors" + "fmt" + "regexp" + + "github.com/SchwarzIT/community-stackit-go-client/pkg/validate" +) + +// Validate validates the given cluster data (dry validation) +func Validate( + clusterName string, + clusterConfig Kubernetes, + nodePools []Nodepool, + maintenance *Maintenance, + hibernation *Hibernation, + extensions *Extension, +) error { + if err := validate.SemVer(clusterConfig.Version); err != nil { + return err + } + if err := ValidateClusterName(clusterName); err != nil { + return err + } + if len(nodePools) == 0 { + return errors.New("at least one node pool must be specified") + } + for _, np := range nodePools { + if err := ValidateNodePool(np); err != nil { + return err + } + } + if err := ValidateMaintenance(maintenance); err != nil { + return err + } + if err := ValidateHibernation(hibernation); err != nil { + return err + } + if err := ValidateExtensions(extensions); err != nil { + return err + } + return nil +} + +// ValidateClusterName validates a given cluster name +func ValidateClusterName(name string) error { + exp := `^[a-z0-9]{1}[a-z0-9-]{0,10}$` + r := regexp.MustCompile(exp) + if !r.MatchString(name) { + return fmt.Errorf("invalid cluster name. valid name is of: %s", exp) + } + return nil +} + +// ValidateNodePoolName validates a given pool name +func ValidateNodePoolName(name string) error { + exp := `^[a-z0-9]{1}[a-z0-9-]{0,14}$` + r := regexp.MustCompile(exp) + if !r.MatchString(name) { + return fmt.Errorf("invalid node pool name. valid name is of: %s", exp) + } + return nil +} + +// ValidateNodePool validates a given node pool +func ValidateNodePool(np Nodepool) error { + if err := ValidateNodePoolName(np.Name); err != nil { + return err + } + if np.Machine.Type == "" { + return errors.New("machine type must be specified") + } + if np.Machine.Image.Version == "" { + return errors.New("machine image version must be specified") + } + if np.Minimum > np.Maximum { + return errors.New("minimum value can't be larger than maximum") + } + if np.Minimum < 1 || np.Minimum > 100 { + return errors.New("minimum value must be in the range of 1..100") + } + if np.Maximum < 1 || np.Maximum > 100 { + return errors.New("maximum value must be in the range of 1..100") + } + if np.MaxSurge != nil { + if *np.MaxSurge < 1 || *np.MaxSurge > 10 { + return errors.New("max surge value must be in the range of 1..10") + } + } + if np.Volume.Size < 20 || np.Volume.Size > 10240 { + return errors.New("volume size value must be in the range of 20..10240") + } + if np.Taints != nil { + for _, t := range *np.Taints { + if err := ValidateTaint(t); err != nil { + return err + } + } + } + if err := ValidateCRI(np.CRI); err != nil { + return err + } + return nil +} + +// ValidateTaint validates a given node pool taint +func ValidateTaint(t Taint) error { + switch t.Effect { + case NO_EXECUTE: + fallthrough + case NO_SCHEDULE: + fallthrough + case PREFER_NO_SCHEDULE: + default: + return fmt.Errorf("invalid taint effect '%s'", t.Effect) + } + + if t.Key == "" { + return errors.New("taint key is required") + } + return nil +} + +// ValidateCRI validates the given cri struct +func ValidateCRI(c *CRI) error { + if c == nil { + return nil + } + if c.Name == nil { + return nil + } + switch *c.Name { + case CONTAINERD: + fallthrough + case DOCKER: + default: + return fmt.Errorf("invalid CRI name '%s'", string(*c.Name)) + } + return nil +} + +// ValidateMaintenance validates a given cluster maintenance +func ValidateMaintenance(m *Maintenance) error { + if m == nil { + return nil + } + if m.TimeWindow.End == "" { + return errors.New("maintenance end time window is required") + } + if m.TimeWindow.Start == "" { + return errors.New("maintenance start time window is required") + } + return nil +} + +// ValidateHibernation validates a given cluster hibernation +func ValidateHibernation(h *Hibernation) error { + if h == nil { + return nil + } + for _, s := range h.Schedules { + if s.End == "" { + return errors.New("hibernation end time is required") + } + if s.Start == "" { + return errors.New("hibernation start time is required") + } + } + return nil +} + +// ValidateExtensions validates a given cluster extensions +func ValidateExtensions(e *Extension) error { + if e == nil { + return nil + } + if e.Argus != nil { + if e.Argus.Enabled && e.Argus.ArgusInstanceID == "" { + return errors.New("argus instance ID is mandatory when Argus is enabled") + } + } + return nil +} diff --git a/pkg/services/kubernetes/v1.1/cluster/wait.go b/pkg/services/kubernetes/v1.1/cluster/wait.go new file mode 100644 index 00000000..f0f049bc --- /dev/null +++ b/pkg/services/kubernetes/v1.1/cluster/wait.go @@ -0,0 +1,58 @@ +package cluster + +import ( + "context" + "net/http" + "strings" + + "github.com/SchwarzIT/community-stackit-go-client/pkg/wait" +) + +func (*CreateOrUpdateResponse) WaitHandler(ctx context.Context, c *ClientWithResponses, projectID, clusterName string) *wait.Handler { + return wait.New(func() (res interface{}, done bool, err error) { + resp, err := c.Get(ctx, projectID, clusterName) + if err != nil { + if strings.Contains(err.Error(), http.StatusText(http.StatusForbidden)) { + return nil, false, nil + } + return nil, false, err + } + if resp.StatusCode() == http.StatusForbidden { + return nil, false, nil + } + if resp.StatusCode() == http.StatusInternalServerError { + return nil, false, nil + } + if resp.Error != nil { + return nil, false, resp.Error + } + + status := *resp.JSON200.Status.Aggregated + if status == STATE_HEALTHY || status == STATE_HIBERNATED { + return resp, true, nil + } + return resp, false, nil + }) +} + +func (*DeleteResponse) WaitHandler(ctx context.Context, c *ClientWithResponses, projectID, clusterName string) *wait.Handler { + return wait.New(func() (res interface{}, done bool, err error) { + resp, err := c.Get(ctx, projectID, clusterName) + if err != nil { + if strings.Contains(err.Error(), http.StatusText(http.StatusNotFound)) { + return nil, true, nil + } + return nil, false, err + } + if resp.StatusCode() == http.StatusInternalServerError { + return nil, false, nil + } + if resp.Error != nil { + if resp.StatusCode() == http.StatusNotFound { + return nil, true, nil + } + return nil, false, err + } + return nil, false, nil + }) +} diff --git a/pkg/services/kubernetes/v1.1/credentials/credentials.go b/pkg/services/kubernetes/v1.1/credentials/credentials.go new file mode 100644 index 00000000..2f7c6d70 --- /dev/null +++ b/pkg/services/kubernetes/v1.1/credentials/credentials.go @@ -0,0 +1,912 @@ +// Package credentials provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/do87/stackit-client-generator version v0.0.2 DO NOT EDIT. +package credentials + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "strings" + + "github.com/pkg/errors" + + contracts "github.com/SchwarzIT/community-stackit-go-client/pkg/contracts" + "github.com/SchwarzIT/community-stackit-go-client/pkg/helpers/runtime" + "github.com/SchwarzIT/community-stackit-go-client/pkg/validate" +) + +const ( + BearerAuthScopes = "bearerAuth.Scopes" +) + +// Defines values for RuntimeErrorCode. +const ( + SKE_API_SERVER_ERROR RuntimeErrorCode = "SKE_API_SERVER_ERROR" + SKE_ARGUS_INSTANCE_NOT_FOUND RuntimeErrorCode = "SKE_ARGUS_INSTANCE_NOT_FOUND" + SKE_CONFIGURATION_PROBLEM RuntimeErrorCode = "SKE_CONFIGURATION_PROBLEM" + SKE_INFRA_ERROR RuntimeErrorCode = "SKE_INFRA_ERROR" + SKE_QUOTA_EXCEEDED RuntimeErrorCode = "SKE_QUOTA_EXCEEDED" + SKE_RATE_LIMITS RuntimeErrorCode = "SKE_RATE_LIMITS" + SKE_REMAINING_RESOURCES RuntimeErrorCode = "SKE_REMAINING_RESOURCES" + SKE_TMP_AUTH_ERROR RuntimeErrorCode = "SKE_TMP_AUTH_ERROR" + SKE_UNREADY_NODES RuntimeErrorCode = "SKE_UNREADY_NODES" + SKE_UNSPECIFIED RuntimeErrorCode = "SKE_UNSPECIFIED" +) + +// Credentials defines model for Credentials. +type Credentials struct { + CertificateAuthorityData *string `json:"certificateAuthorityData,omitempty"` + + // Kubeconfig This string contains the kubeconfig as yaml. + Kubeconfig *string `json:"kubeconfig,omitempty"` + Server *string `json:"server,omitempty"` + Token *string `json:"token,omitempty"` +} + +// Kubeconfig defines model for Kubeconfig. +type Kubeconfig struct { + ExpirationTimestamp *string `json:"expirationTimestamp,omitempty"` + Kubeconfig *string `json:"kubeconfig,omitempty"` +} + +// KubeconfigRequest defines model for KubeconfigRequest. +type KubeconfigRequest struct { + ExpirationSeconds *string `json:"expirationSeconds,omitempty"` +} + +// RuntimeError defines model for RuntimeError. +type RuntimeError struct { + // Code - Code: `SKE_UNSPECIFIED` + // Message: "An error occurred. Please open a support ticket if this error persists." + // - Code: `SKE_TMP_AUTH_ERROR` + // Message: "Authentication failed. This is a temporary error. Please wait while the system recovers." + // - Code: `SKE_QUOTA_EXCEEDED` + // Message: "Your project's resource quotas are exhausted. Please make sure your quota is sufficient for the ordered cluster." + // - Code: `SKE_ARGUS_INSTANCE_NOT_FOUND` + // Message: "The provided Argus instance could not be found." + // - Code: `SKE_RATE_LIMITS` + // Message: "While provisioning your cluster, request rate limits where incurred. Please wait while the system recovers." + // - Code: `SKE_INFRA_ERROR` + // Message: "An error occurred with the underlying infrastructure. Please open a support ticket if this error persists." + // - Code: `SKE_REMAINING_RESOURCES` + // Message: "There are remaining Kubernetes resources in your cluster that prevent deletion. Please make sure to remove them." + // - Code: `SKE_CONFIGURATION_PROBLEM` + // Message: "A configuration error occurred. Please open a support ticket if this error persists." + // - Code: `SKE_UNREADY_NODES` + // Message: "Not all worker nodes are ready. Please open a support ticket if this error persists." + // - Code: `SKE_API_SERVER_ERROR` + // Message: "The Kubernetes API server is not reporting readiness. Please open a support ticket if this error persists." + Code *RuntimeErrorCode `json:"code,omitempty"` + Details *string `json:"details,omitempty"` + Message *string `json:"message,omitempty"` +} + +// RuntimeErrorCode - Code: `SKE_UNSPECIFIED` +// +// Message: "An error occurred. Please open a support ticket if this error persists." +// - Code: `SKE_TMP_AUTH_ERROR` +// Message: "Authentication failed. This is a temporary error. Please wait while the system recovers." +// - Code: `SKE_QUOTA_EXCEEDED` +// Message: "Your project's resource quotas are exhausted. Please make sure your quota is sufficient for the ordered cluster." +// - Code: `SKE_ARGUS_INSTANCE_NOT_FOUND` +// Message: "The provided Argus instance could not be found." +// - Code: `SKE_RATE_LIMITS` +// Message: "While provisioning your cluster, request rate limits where incurred. Please wait while the system recovers." +// - Code: `SKE_INFRA_ERROR` +// Message: "An error occurred with the underlying infrastructure. Please open a support ticket if this error persists." +// - Code: `SKE_REMAINING_RESOURCES` +// Message: "There are remaining Kubernetes resources in your cluster that prevent deletion. Please make sure to remove them." +// - Code: `SKE_CONFIGURATION_PROBLEM` +// Message: "A configuration error occurred. Please open a support ticket if this error persists." +// - Code: `SKE_UNREADY_NODES` +// Message: "Not all worker nodes are ready. Please open a support ticket if this error persists." +// - Code: `SKE_API_SERVER_ERROR` +// Message: "The Kubernetes API server is not reporting readiness. Please open a support ticket if this error persists." +type RuntimeErrorCode string + +// CreateKubeconfigJSONRequestBody defines body for CreateKubeconfig for application/json ContentType. +type CreateKubeconfigJSONRequestBody = KubeconfigRequest + +// RequestEditorFn is the function signature for the RequestEditor callback function +type RequestEditorFn func(ctx context.Context, req *http.Request) error + +// Client which conforms to the OpenAPI3 specification for this service. +type Client struct { + // The endpoint of the server conforming to this interface, with scheme, + // https://api.deepmap.com for example. This can contain a path relative + // to the server, such as https://api.deepmap.com/dev-test, and all the + // paths in the swagger spec will be appended to the server. + Server string + + // Doer for performing requests, typically a *http.Client with any + // customized settings, such as certificate chains. + Client contracts.BaseClientInterface +} + +// NewRawClient Creates a new Client, with reasonable defaults +func NewRawClient(server string, httpClient contracts.BaseClientInterface) *Client { + // create a client with sane default values + client := Client{ + Server: server, + Client: httpClient, + } + return &client +} + +// The interface specification for the client above. +type rawClientInterface interface { + // CompleteClusterCredentialsRotation request + CompleteClusterCredentialsRotationRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // List request + ListRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // CreateKubeconfig request with any body + CreateKubeconfigRawWithBody(ctx context.Context, projectID string, clusterName string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + CreateKubeconfigRaw(ctx context.Context, projectID string, clusterName string, body CreateKubeconfigJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // TriggerRotation request + TriggerRotationRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // StartClusterCredentialsRotation request + StartClusterCredentialsRotationRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) +} + +func (c *Client) CompleteClusterCredentialsRotationRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCompleteClusterCredentialsRotationRequest(ctx, c.Server, projectID, clusterName) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) ListRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewListRequest(ctx, c.Server, projectID, clusterName) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) CreateKubeconfigRawWithBody(ctx context.Context, projectID string, clusterName string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateKubeconfigRequestWithBody(ctx, c.Server, projectID, clusterName, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) CreateKubeconfigRaw(ctx context.Context, projectID string, clusterName string, body CreateKubeconfigJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateKubeconfigRequest(ctx, c.Server, projectID, clusterName, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) TriggerRotationRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewTriggerRotationRequest(ctx, c.Server, projectID, clusterName) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) StartClusterCredentialsRotationRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewStartClusterCredentialsRotationRequest(ctx, c.Server, projectID, clusterName) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +// NewCompleteClusterCredentialsRotationRequest generates requests for CompleteClusterCredentialsRotation +func NewCompleteClusterCredentialsRotationRequest(ctx context.Context, server string, projectID string, clusterName string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "clusterName", runtime.ParamLocationPath, clusterName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters/%s/complete-credentials-rotation", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "POST", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewListRequest generates requests for List +func NewListRequest(ctx context.Context, server string, projectID string, clusterName string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "clusterName", runtime.ParamLocationPath, clusterName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters/%s/credentials", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewCreateKubeconfigRequest calls the generic CreateKubeconfig builder with application/json body +func NewCreateKubeconfigRequest(ctx context.Context, server string, projectID string, clusterName string, body CreateKubeconfigJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewCreateKubeconfigRequestWithBody(ctx, server, projectID, clusterName, "application/json", bodyReader) +} + +// NewCreateKubeconfigRequestWithBody generates requests for CreateKubeconfig with any type of body +func NewCreateKubeconfigRequestWithBody(ctx context.Context, server string, projectID string, clusterName string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "clusterName", runtime.ParamLocationPath, clusterName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters/%s/kubeconfig", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewTriggerRotationRequest generates requests for TriggerRotation +func NewTriggerRotationRequest(ctx context.Context, server string, projectID string, clusterName string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "clusterName", runtime.ParamLocationPath, clusterName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters/%s/rotate-credentials", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "POST", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewStartClusterCredentialsRotationRequest generates requests for StartClusterCredentialsRotation +func NewStartClusterCredentialsRotationRequest(ctx context.Context, server string, projectID string, clusterName string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "clusterName", runtime.ParamLocationPath, clusterName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters/%s/start-credentials-rotation", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "POST", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { + for _, r := range additionalEditors { + if err := r(ctx, req); err != nil { + return err + } + } + return nil +} + +// ClientWithResponses builds on rawClientInterface to offer response payloads +type ClientWithResponses struct { + rawClientInterface +} + +// NewClient creates a new ClientWithResponses, which wraps +// Client with return type handling +func NewClient(server string, httpClient contracts.BaseClientInterface) *ClientWithResponses { + return &ClientWithResponses{NewRawClient(server, httpClient)} +} + +// ClientWithResponsesInterface is the interface specification for the client with responses above. +type ClientWithResponsesInterface interface { + // CompleteClusterCredentialsRotation request + CompleteClusterCredentialsRotation(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*CompleteClusterCredentialsRotationResponse, error) + + // List request + List(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*ListResponse, error) + + // CreateKubeconfig request with any body + CreateKubeconfigWithBody(ctx context.Context, projectID string, clusterName string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateKubeconfigResponse, error) + + CreateKubeconfig(ctx context.Context, projectID string, clusterName string, body CreateKubeconfigJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateKubeconfigResponse, error) + + // TriggerRotation request + TriggerRotation(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*TriggerRotationResponse, error) + + // StartClusterCredentialsRotation request + StartClusterCredentialsRotation(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*StartClusterCredentialsRotationResponse, error) +} + +type CompleteClusterCredentialsRotationResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *map[string]interface{} + JSON202 *map[string]interface{} + JSON400 *map[string]interface{} + JSON404 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r CompleteClusterCredentialsRotationResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r CompleteClusterCredentialsRotationResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type ListResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Credentials + JSON400 *map[string]interface{} + JSON404 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r ListResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r ListResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type CreateKubeconfigResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Kubeconfig + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r CreateKubeconfigResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r CreateKubeconfigResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type TriggerRotationResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *map[string]interface{} + JSON202 *map[string]interface{} + JSON404 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r TriggerRotationResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r TriggerRotationResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type StartClusterCredentialsRotationResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *map[string]interface{} + JSON202 *map[string]interface{} + JSON400 *map[string]interface{} + JSON404 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r StartClusterCredentialsRotationResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r StartClusterCredentialsRotationResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// CompleteClusterCredentialsRotation request returning *CompleteClusterCredentialsRotationResponse +func (c *ClientWithResponses) CompleteClusterCredentialsRotation(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*CompleteClusterCredentialsRotationResponse, error) { + rsp, err := c.CompleteClusterCredentialsRotationRaw(ctx, projectID, clusterName, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseCompleteClusterCredentialsRotationResponse(rsp) +} + +// List request returning *ListResponse +func (c *ClientWithResponses) List(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*ListResponse, error) { + rsp, err := c.ListRaw(ctx, projectID, clusterName, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseListResponse(rsp) +} + +// CreateKubeconfigWithBody request with arbitrary body returning *CreateKubeconfigResponse +func (c *ClientWithResponses) CreateKubeconfigWithBody(ctx context.Context, projectID string, clusterName string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateKubeconfigResponse, error) { + rsp, err := c.CreateKubeconfigRawWithBody(ctx, projectID, clusterName, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseCreateKubeconfigResponse(rsp) +} + +func (c *ClientWithResponses) CreateKubeconfig(ctx context.Context, projectID string, clusterName string, body CreateKubeconfigJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateKubeconfigResponse, error) { + rsp, err := c.CreateKubeconfigRaw(ctx, projectID, clusterName, body, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseCreateKubeconfigResponse(rsp) +} + +// TriggerRotation request returning *TriggerRotationResponse +func (c *ClientWithResponses) TriggerRotation(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*TriggerRotationResponse, error) { + rsp, err := c.TriggerRotationRaw(ctx, projectID, clusterName, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseTriggerRotationResponse(rsp) +} + +// StartClusterCredentialsRotation request returning *StartClusterCredentialsRotationResponse +func (c *ClientWithResponses) StartClusterCredentialsRotation(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*StartClusterCredentialsRotationResponse, error) { + rsp, err := c.StartClusterCredentialsRotationRaw(ctx, projectID, clusterName, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseStartClusterCredentialsRotationResponse(rsp) +} + +// ParseCompleteClusterCredentialsRotationResponse parses an HTTP response from a CompleteClusterCredentialsRotation call +func (c *ClientWithResponses) ParseCompleteClusterCredentialsRotationResponse(rsp *http.Response) (*CompleteClusterCredentialsRotationResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &CompleteClusterCredentialsRotationResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 202: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON202 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseListResponse parses an HTTP response from a List call +func (c *ClientWithResponses) ParseListResponse(rsp *http.Response) (*ListResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &ListResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Credentials + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseCreateKubeconfigResponse parses an HTTP response from a CreateKubeconfig call +func (c *ClientWithResponses) ParseCreateKubeconfigResponse(rsp *http.Response) (*CreateKubeconfigResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &CreateKubeconfigResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Kubeconfig + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseTriggerRotationResponse parses an HTTP response from a TriggerRotation call +func (c *ClientWithResponses) ParseTriggerRotationResponse(rsp *http.Response) (*TriggerRotationResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &TriggerRotationResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 202: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON202 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseStartClusterCredentialsRotationResponse parses an HTTP response from a StartClusterCredentialsRotation call +func (c *ClientWithResponses) ParseStartClusterCredentialsRotationResponse(rsp *http.Response) (*StartClusterCredentialsRotationResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &StartClusterCredentialsRotationResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 202: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON202 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} diff --git a/pkg/services/kubernetes/v1.1/kubernetes.go b/pkg/services/kubernetes/v1.1/kubernetes.go new file mode 100644 index 00000000..53265bc9 --- /dev/null +++ b/pkg/services/kubernetes/v1.1/kubernetes.go @@ -0,0 +1,115 @@ +// Package kubernetes provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/do87/stackit-client-generator version v0.0.2 DO NOT EDIT. +package kubernetes + +import ( + "net/url" + "strings" + + contracts "github.com/SchwarzIT/community-stackit-go-client/pkg/contracts" + "github.com/SchwarzIT/community-stackit-go-client/pkg/services/kubernetes/v1.0/cluster" + "github.com/SchwarzIT/community-stackit-go-client/pkg/services/kubernetes/v1.0/credentials" + "github.com/SchwarzIT/community-stackit-go-client/pkg/services/kubernetes/v1.0/operation" + "github.com/SchwarzIT/community-stackit-go-client/pkg/services/kubernetes/v1.0/project" + provideroptions "github.com/SchwarzIT/community-stackit-go-client/pkg/services/kubernetes/v1.0/provider-options" +) + +// Client which conforms to the OpenAPI3 specification for this service. +type Client struct { + // list of connected client services + Cluster *cluster.Client + Credentials *credentials.Client + Operation *operation.Client + ProviderOptions *provideroptions.Client + Project *project.Client + + // The endpoint of the server conforming to this interface, with scheme, + // https://api.deepmap.com for example. This can contain a path relative + // to the server, such as https://api.deepmap.com/dev-test, and all the + // paths in the swagger spec will be appended to the server. + Server string + + // Doer for performing requests, typically a *http.Client with any + // customized settings, such as certificate chains. + Client contracts.BaseClientInterface +} + +// ClientOption allows setting custom parameters during construction +type ClientOption func(*Client) error + +func NewRawClient(server string, opts ...ClientOption) (*Client, error) { + // create a factory client + client := Client{ + Server: server, + } + // mutate client and add all optional params + for _, o := range opts { + if err := o(&client); err != nil { + return nil, err + } + } + // ensure the server URL always has a trailing slash + if !strings.HasSuffix(client.Server, "/") { + client.Server += "/" + } + + client.Cluster = cluster.NewRawClient(server, client.Client) + client.Credentials = credentials.NewRawClient(server, client.Client) + client.Operation = operation.NewRawClient(server, client.Client) + client.ProviderOptions = provideroptions.NewRawClient(server, client.Client) + client.Project = project.NewRawClient(server, client.Client) + + return &client, nil +} + +// WithHTTPClient allows overriding the default Doer, which is +// automatically created using http.Client. This is useful for tests. +func WithHTTPClient(doer contracts.BaseClientInterface) ClientOption { + return func(c *Client) error { + c.Client = doer + return nil + } +} + +// WithBaseURL overrides the baseURL. +func WithBaseURL(baseURL string) ClientOption { + return func(c *Client) error { + newBaseURL, err := url.Parse(baseURL) + if err != nil { + return err + } + c.Server = newBaseURL.String() + return nil + } +} + +// ClientWithResponses builds on rawClientInterface to offer response payloads +type ClientWithResponses struct { + Client *Client + + // list of connected client services + Cluster *cluster.ClientWithResponses + Credentials *credentials.ClientWithResponses + Operation *operation.ClientWithResponses + ProviderOptions *provideroptions.ClientWithResponses + Project *project.ClientWithResponses +} + +// NewClient creates a new ClientWithResponses, which wraps +// Client with return type handling +func NewClient(server string, opts ...ClientOption) (*ClientWithResponses, error) { + client, err := NewRawClient(server, opts...) + if err != nil { + return nil, err + } + + cwr := &ClientWithResponses{Client: client} + cwr.Cluster = cluster.NewClient(server, client.Client) + cwr.Credentials = credentials.NewClient(server, client.Client) + cwr.Operation = operation.NewClient(server, client.Client) + cwr.ProviderOptions = provideroptions.NewClient(server, client.Client) + cwr.Project = project.NewClient(server, client.Client) + + return cwr, nil +} diff --git a/pkg/services/kubernetes/v1.1/operation/operation.go b/pkg/services/kubernetes/v1.1/operation/operation.go new file mode 100644 index 00000000..38182cf2 --- /dev/null +++ b/pkg/services/kubernetes/v1.1/operation/operation.go @@ -0,0 +1,1328 @@ +// Package operation provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/do87/stackit-client-generator version v0.0.2 DO NOT EDIT. +package operation + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "strings" + + "github.com/pkg/errors" + + contracts "github.com/SchwarzIT/community-stackit-go-client/pkg/contracts" + "github.com/SchwarzIT/community-stackit-go-client/pkg/helpers/runtime" + "github.com/SchwarzIT/community-stackit-go-client/pkg/validate" +) + +const ( + BearerAuthScopes = "bearerAuth.Scopes" +) + +// Defines values for RuntimeErrorCode. +const ( + SKE_API_SERVER_ERROR RuntimeErrorCode = "SKE_API_SERVER_ERROR" + SKE_ARGUS_INSTANCE_NOT_FOUND RuntimeErrorCode = "SKE_ARGUS_INSTANCE_NOT_FOUND" + SKE_CONFIGURATION_PROBLEM RuntimeErrorCode = "SKE_CONFIGURATION_PROBLEM" + SKE_INFRA_ERROR RuntimeErrorCode = "SKE_INFRA_ERROR" + SKE_QUOTA_EXCEEDED RuntimeErrorCode = "SKE_QUOTA_EXCEEDED" + SKE_RATE_LIMITS RuntimeErrorCode = "SKE_RATE_LIMITS" + SKE_REMAINING_RESOURCES RuntimeErrorCode = "SKE_REMAINING_RESOURCES" + SKE_TMP_AUTH_ERROR RuntimeErrorCode = "SKE_TMP_AUTH_ERROR" + SKE_UNREADY_NODES RuntimeErrorCode = "SKE_UNREADY_NODES" + SKE_UNSPECIFIED RuntimeErrorCode = "SKE_UNSPECIFIED" +) + +// Kubeconfig defines model for Kubeconfig. +type Kubeconfig struct { + ExpirationTimestamp *string `json:"expirationTimestamp,omitempty"` + Kubeconfig *string `json:"kubeconfig,omitempty"` +} + +// KubeconfigRequest defines model for KubeconfigRequest. +type KubeconfigRequest struct { + ExpirationSeconds *string `json:"expirationSeconds,omitempty"` +} + +// RuntimeError defines model for RuntimeError. +type RuntimeError struct { + // Code - Code: `SKE_UNSPECIFIED` + // Message: "An error occurred. Please open a support ticket if this error persists." + // - Code: `SKE_TMP_AUTH_ERROR` + // Message: "Authentication failed. This is a temporary error. Please wait while the system recovers." + // - Code: `SKE_QUOTA_EXCEEDED` + // Message: "Your project's resource quotas are exhausted. Please make sure your quota is sufficient for the ordered cluster." + // - Code: `SKE_ARGUS_INSTANCE_NOT_FOUND` + // Message: "The provided Argus instance could not be found." + // - Code: `SKE_RATE_LIMITS` + // Message: "While provisioning your cluster, request rate limits where incurred. Please wait while the system recovers." + // - Code: `SKE_INFRA_ERROR` + // Message: "An error occurred with the underlying infrastructure. Please open a support ticket if this error persists." + // - Code: `SKE_REMAINING_RESOURCES` + // Message: "There are remaining Kubernetes resources in your cluster that prevent deletion. Please make sure to remove them." + // - Code: `SKE_CONFIGURATION_PROBLEM` + // Message: "A configuration error occurred. Please open a support ticket if this error persists." + // - Code: `SKE_UNREADY_NODES` + // Message: "Not all worker nodes are ready. Please open a support ticket if this error persists." + // - Code: `SKE_API_SERVER_ERROR` + // Message: "The Kubernetes API server is not reporting readiness. Please open a support ticket if this error persists." + Code *RuntimeErrorCode `json:"code,omitempty"` + Details *string `json:"details,omitempty"` + Message *string `json:"message,omitempty"` +} + +// RuntimeErrorCode - Code: `SKE_UNSPECIFIED` +// +// Message: "An error occurred. Please open a support ticket if this error persists." +// - Code: `SKE_TMP_AUTH_ERROR` +// Message: "Authentication failed. This is a temporary error. Please wait while the system recovers." +// - Code: `SKE_QUOTA_EXCEEDED` +// Message: "Your project's resource quotas are exhausted. Please make sure your quota is sufficient for the ordered cluster." +// - Code: `SKE_ARGUS_INSTANCE_NOT_FOUND` +// Message: "The provided Argus instance could not be found." +// - Code: `SKE_RATE_LIMITS` +// Message: "While provisioning your cluster, request rate limits where incurred. Please wait while the system recovers." +// - Code: `SKE_INFRA_ERROR` +// Message: "An error occurred with the underlying infrastructure. Please open a support ticket if this error persists." +// - Code: `SKE_REMAINING_RESOURCES` +// Message: "There are remaining Kubernetes resources in your cluster that prevent deletion. Please make sure to remove them." +// - Code: `SKE_CONFIGURATION_PROBLEM` +// Message: "A configuration error occurred. Please open a support ticket if this error persists." +// - Code: `SKE_UNREADY_NODES` +// Message: "Not all worker nodes are ready. Please open a support ticket if this error persists." +// - Code: `SKE_API_SERVER_ERROR` +// Message: "The Kubernetes API server is not reporting readiness. Please open a support ticket if this error persists." +type RuntimeErrorCode string + +// CreateKubeconfigJSONRequestBody defines body for CreateKubeconfig for application/json ContentType. +type CreateKubeconfigJSONRequestBody = KubeconfigRequest + +// RequestEditorFn is the function signature for the RequestEditor callback function +type RequestEditorFn func(ctx context.Context, req *http.Request) error + +// Client which conforms to the OpenAPI3 specification for this service. +type Client struct { + // The endpoint of the server conforming to this interface, with scheme, + // https://api.deepmap.com for example. This can contain a path relative + // to the server, such as https://api.deepmap.com/dev-test, and all the + // paths in the swagger spec will be appended to the server. + Server string + + // Doer for performing requests, typically a *http.Client with any + // customized settings, such as certificate chains. + Client contracts.BaseClientInterface +} + +// NewRawClient Creates a new Client, with reasonable defaults +func NewRawClient(server string, httpClient contracts.BaseClientInterface) *Client { + // create a client with sane default values + client := Client{ + Server: server, + Client: httpClient, + } + return &client +} + +// The interface specification for the client above. +type rawClientInterface interface { + // CompleteClusterCredentialsRotation request + CompleteClusterCredentialsRotationRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // TriggerHibernation request + TriggerHibernationRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // CreateKubeconfig request with any body + CreateKubeconfigRawWithBody(ctx context.Context, projectID string, clusterName string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + CreateKubeconfigRaw(ctx context.Context, projectID string, clusterName string, body CreateKubeconfigJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // TriggerMaintenance request + TriggerMaintenanceRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // TriggerReconciliation request + TriggerReconciliationRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // TriggerRotation request + TriggerRotationRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // StartClusterCredentialsRotation request + StartClusterCredentialsRotationRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // TriggerWakeup request + TriggerWakeupRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) +} + +func (c *Client) CompleteClusterCredentialsRotationRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCompleteClusterCredentialsRotationRequest(ctx, c.Server, projectID, clusterName) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) TriggerHibernationRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewTriggerHibernationRequest(ctx, c.Server, projectID, clusterName) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) CreateKubeconfigRawWithBody(ctx context.Context, projectID string, clusterName string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateKubeconfigRequestWithBody(ctx, c.Server, projectID, clusterName, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) CreateKubeconfigRaw(ctx context.Context, projectID string, clusterName string, body CreateKubeconfigJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateKubeconfigRequest(ctx, c.Server, projectID, clusterName, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) TriggerMaintenanceRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewTriggerMaintenanceRequest(ctx, c.Server, projectID, clusterName) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) TriggerReconciliationRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewTriggerReconciliationRequest(ctx, c.Server, projectID, clusterName) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) TriggerRotationRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewTriggerRotationRequest(ctx, c.Server, projectID, clusterName) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) StartClusterCredentialsRotationRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewStartClusterCredentialsRotationRequest(ctx, c.Server, projectID, clusterName) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) TriggerWakeupRaw(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewTriggerWakeupRequest(ctx, c.Server, projectID, clusterName) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +// NewCompleteClusterCredentialsRotationRequest generates requests for CompleteClusterCredentialsRotation +func NewCompleteClusterCredentialsRotationRequest(ctx context.Context, server string, projectID string, clusterName string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "clusterName", runtime.ParamLocationPath, clusterName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters/%s/complete-credentials-rotation", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "POST", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewTriggerHibernationRequest generates requests for TriggerHibernation +func NewTriggerHibernationRequest(ctx context.Context, server string, projectID string, clusterName string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "clusterName", runtime.ParamLocationPath, clusterName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters/%s/hibernate", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "POST", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewCreateKubeconfigRequest calls the generic CreateKubeconfig builder with application/json body +func NewCreateKubeconfigRequest(ctx context.Context, server string, projectID string, clusterName string, body CreateKubeconfigJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewCreateKubeconfigRequestWithBody(ctx, server, projectID, clusterName, "application/json", bodyReader) +} + +// NewCreateKubeconfigRequestWithBody generates requests for CreateKubeconfig with any type of body +func NewCreateKubeconfigRequestWithBody(ctx context.Context, server string, projectID string, clusterName string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "clusterName", runtime.ParamLocationPath, clusterName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters/%s/kubeconfig", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + +// NewTriggerMaintenanceRequest generates requests for TriggerMaintenance +func NewTriggerMaintenanceRequest(ctx context.Context, server string, projectID string, clusterName string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "clusterName", runtime.ParamLocationPath, clusterName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters/%s/maintenance", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "POST", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewTriggerReconciliationRequest generates requests for TriggerReconciliation +func NewTriggerReconciliationRequest(ctx context.Context, server string, projectID string, clusterName string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "clusterName", runtime.ParamLocationPath, clusterName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters/%s/reconcile", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "POST", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewTriggerRotationRequest generates requests for TriggerRotation +func NewTriggerRotationRequest(ctx context.Context, server string, projectID string, clusterName string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "clusterName", runtime.ParamLocationPath, clusterName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters/%s/rotate-credentials", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "POST", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewStartClusterCredentialsRotationRequest generates requests for StartClusterCredentialsRotation +func NewStartClusterCredentialsRotationRequest(ctx context.Context, server string, projectID string, clusterName string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "clusterName", runtime.ParamLocationPath, clusterName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters/%s/start-credentials-rotation", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "POST", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewTriggerWakeupRequest generates requests for TriggerWakeup +func NewTriggerWakeupRequest(ctx context.Context, server string, projectID string, clusterName string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "clusterName", runtime.ParamLocationPath, clusterName) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s/clusters/%s/wakeup", pathParam0, pathParam1) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "POST", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { + for _, r := range additionalEditors { + if err := r(ctx, req); err != nil { + return err + } + } + return nil +} + +// ClientWithResponses builds on rawClientInterface to offer response payloads +type ClientWithResponses struct { + rawClientInterface +} + +// NewClient creates a new ClientWithResponses, which wraps +// Client with return type handling +func NewClient(server string, httpClient contracts.BaseClientInterface) *ClientWithResponses { + return &ClientWithResponses{NewRawClient(server, httpClient)} +} + +// ClientWithResponsesInterface is the interface specification for the client with responses above. +type ClientWithResponsesInterface interface { + // CompleteClusterCredentialsRotation request + CompleteClusterCredentialsRotation(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*CompleteClusterCredentialsRotationResponse, error) + + // TriggerHibernation request + TriggerHibernation(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*TriggerHibernationResponse, error) + + // CreateKubeconfig request with any body + CreateKubeconfigWithBody(ctx context.Context, projectID string, clusterName string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateKubeconfigResponse, error) + + CreateKubeconfig(ctx context.Context, projectID string, clusterName string, body CreateKubeconfigJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateKubeconfigResponse, error) + + // TriggerMaintenance request + TriggerMaintenance(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*TriggerMaintenanceResponse, error) + + // TriggerReconciliation request + TriggerReconciliation(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*TriggerReconciliationResponse, error) + + // TriggerRotation request + TriggerRotation(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*TriggerRotationResponse, error) + + // StartClusterCredentialsRotation request + StartClusterCredentialsRotation(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*StartClusterCredentialsRotationResponse, error) + + // TriggerWakeup request + TriggerWakeup(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*TriggerWakeupResponse, error) +} + +type CompleteClusterCredentialsRotationResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *map[string]interface{} + JSON202 *map[string]interface{} + JSON400 *map[string]interface{} + JSON404 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r CompleteClusterCredentialsRotationResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r CompleteClusterCredentialsRotationResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type TriggerHibernationResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *map[string]interface{} + JSON202 *map[string]interface{} + JSON404 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r TriggerHibernationResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r TriggerHibernationResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type CreateKubeconfigResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Kubeconfig + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r CreateKubeconfigResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r CreateKubeconfigResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type TriggerMaintenanceResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *map[string]interface{} + JSON202 *map[string]interface{} + JSON404 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r TriggerMaintenanceResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r TriggerMaintenanceResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type TriggerReconciliationResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *map[string]interface{} + JSON202 *map[string]interface{} + JSON404 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r TriggerReconciliationResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r TriggerReconciliationResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type TriggerRotationResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *map[string]interface{} + JSON202 *map[string]interface{} + JSON404 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r TriggerRotationResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r TriggerRotationResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type StartClusterCredentialsRotationResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *map[string]interface{} + JSON202 *map[string]interface{} + JSON400 *map[string]interface{} + JSON404 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r StartClusterCredentialsRotationResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r StartClusterCredentialsRotationResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type TriggerWakeupResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *map[string]interface{} + JSON202 *map[string]interface{} + JSON404 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r TriggerWakeupResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r TriggerWakeupResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// CompleteClusterCredentialsRotation request returning *CompleteClusterCredentialsRotationResponse +func (c *ClientWithResponses) CompleteClusterCredentialsRotation(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*CompleteClusterCredentialsRotationResponse, error) { + rsp, err := c.CompleteClusterCredentialsRotationRaw(ctx, projectID, clusterName, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseCompleteClusterCredentialsRotationResponse(rsp) +} + +// TriggerHibernation request returning *TriggerHibernationResponse +func (c *ClientWithResponses) TriggerHibernation(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*TriggerHibernationResponse, error) { + rsp, err := c.TriggerHibernationRaw(ctx, projectID, clusterName, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseTriggerHibernationResponse(rsp) +} + +// CreateKubeconfigWithBody request with arbitrary body returning *CreateKubeconfigResponse +func (c *ClientWithResponses) CreateKubeconfigWithBody(ctx context.Context, projectID string, clusterName string, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateKubeconfigResponse, error) { + rsp, err := c.CreateKubeconfigRawWithBody(ctx, projectID, clusterName, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseCreateKubeconfigResponse(rsp) +} + +func (c *ClientWithResponses) CreateKubeconfig(ctx context.Context, projectID string, clusterName string, body CreateKubeconfigJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateKubeconfigResponse, error) { + rsp, err := c.CreateKubeconfigRaw(ctx, projectID, clusterName, body, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseCreateKubeconfigResponse(rsp) +} + +// TriggerMaintenance request returning *TriggerMaintenanceResponse +func (c *ClientWithResponses) TriggerMaintenance(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*TriggerMaintenanceResponse, error) { + rsp, err := c.TriggerMaintenanceRaw(ctx, projectID, clusterName, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseTriggerMaintenanceResponse(rsp) +} + +// TriggerReconciliation request returning *TriggerReconciliationResponse +func (c *ClientWithResponses) TriggerReconciliation(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*TriggerReconciliationResponse, error) { + rsp, err := c.TriggerReconciliationRaw(ctx, projectID, clusterName, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseTriggerReconciliationResponse(rsp) +} + +// TriggerRotation request returning *TriggerRotationResponse +func (c *ClientWithResponses) TriggerRotation(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*TriggerRotationResponse, error) { + rsp, err := c.TriggerRotationRaw(ctx, projectID, clusterName, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseTriggerRotationResponse(rsp) +} + +// StartClusterCredentialsRotation request returning *StartClusterCredentialsRotationResponse +func (c *ClientWithResponses) StartClusterCredentialsRotation(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*StartClusterCredentialsRotationResponse, error) { + rsp, err := c.StartClusterCredentialsRotationRaw(ctx, projectID, clusterName, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseStartClusterCredentialsRotationResponse(rsp) +} + +// TriggerWakeup request returning *TriggerWakeupResponse +func (c *ClientWithResponses) TriggerWakeup(ctx context.Context, projectID string, clusterName string, reqEditors ...RequestEditorFn) (*TriggerWakeupResponse, error) { + rsp, err := c.TriggerWakeupRaw(ctx, projectID, clusterName, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseTriggerWakeupResponse(rsp) +} + +// ParseCompleteClusterCredentialsRotationResponse parses an HTTP response from a CompleteClusterCredentialsRotation call +func (c *ClientWithResponses) ParseCompleteClusterCredentialsRotationResponse(rsp *http.Response) (*CompleteClusterCredentialsRotationResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &CompleteClusterCredentialsRotationResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 202: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON202 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseTriggerHibernationResponse parses an HTTP response from a TriggerHibernation call +func (c *ClientWithResponses) ParseTriggerHibernationResponse(rsp *http.Response) (*TriggerHibernationResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &TriggerHibernationResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 202: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON202 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseCreateKubeconfigResponse parses an HTTP response from a CreateKubeconfig call +func (c *ClientWithResponses) ParseCreateKubeconfigResponse(rsp *http.Response) (*CreateKubeconfigResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &CreateKubeconfigResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Kubeconfig + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseTriggerMaintenanceResponse parses an HTTP response from a TriggerMaintenance call +func (c *ClientWithResponses) ParseTriggerMaintenanceResponse(rsp *http.Response) (*TriggerMaintenanceResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &TriggerMaintenanceResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 202: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON202 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseTriggerReconciliationResponse parses an HTTP response from a TriggerReconciliation call +func (c *ClientWithResponses) ParseTriggerReconciliationResponse(rsp *http.Response) (*TriggerReconciliationResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &TriggerReconciliationResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 202: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON202 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseTriggerRotationResponse parses an HTTP response from a TriggerRotation call +func (c *ClientWithResponses) ParseTriggerRotationResponse(rsp *http.Response) (*TriggerRotationResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &TriggerRotationResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 202: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON202 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseStartClusterCredentialsRotationResponse parses an HTTP response from a StartClusterCredentialsRotation call +func (c *ClientWithResponses) ParseStartClusterCredentialsRotationResponse(rsp *http.Response) (*StartClusterCredentialsRotationResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &StartClusterCredentialsRotationResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 202: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON202 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseTriggerWakeupResponse parses an HTTP response from a TriggerWakeup call +func (c *ClientWithResponses) ParseTriggerWakeupResponse(rsp *http.Response) (*TriggerWakeupResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &TriggerWakeupResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 202: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON202 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} diff --git a/pkg/services/kubernetes/v1.1/project/project.go b/pkg/services/kubernetes/v1.1/project/project.go new file mode 100644 index 00000000..4c7a2664 --- /dev/null +++ b/pkg/services/kubernetes/v1.1/project/project.go @@ -0,0 +1,547 @@ +// Package project provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/do87/stackit-client-generator version v0.0.2 DO NOT EDIT. +package project + +import ( + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "strings" + + "github.com/pkg/errors" + + contracts "github.com/SchwarzIT/community-stackit-go-client/pkg/contracts" + "github.com/SchwarzIT/community-stackit-go-client/pkg/helpers/runtime" + "github.com/SchwarzIT/community-stackit-go-client/pkg/validate" +) + +const ( + BearerAuthScopes = "bearerAuth.Scopes" +) + +// Defines values for ProjectState. +const ( + STATE_CREATED ProjectState = "STATE_CREATED" + STATE_CREATING ProjectState = "STATE_CREATING" + STATE_DELETING ProjectState = "STATE_DELETING" + STATE_FAILED ProjectState = "STATE_FAILED" + STATE_UNSPECIFIED ProjectState = "STATE_UNSPECIFIED" +) + +// Defines values for RuntimeErrorCode. +const ( + SKE_API_SERVER_ERROR RuntimeErrorCode = "SKE_API_SERVER_ERROR" + SKE_ARGUS_INSTANCE_NOT_FOUND RuntimeErrorCode = "SKE_ARGUS_INSTANCE_NOT_FOUND" + SKE_CONFIGURATION_PROBLEM RuntimeErrorCode = "SKE_CONFIGURATION_PROBLEM" + SKE_INFRA_ERROR RuntimeErrorCode = "SKE_INFRA_ERROR" + SKE_QUOTA_EXCEEDED RuntimeErrorCode = "SKE_QUOTA_EXCEEDED" + SKE_RATE_LIMITS RuntimeErrorCode = "SKE_RATE_LIMITS" + SKE_REMAINING_RESOURCES RuntimeErrorCode = "SKE_REMAINING_RESOURCES" + SKE_TMP_AUTH_ERROR RuntimeErrorCode = "SKE_TMP_AUTH_ERROR" + SKE_UNREADY_NODES RuntimeErrorCode = "SKE_UNREADY_NODES" + SKE_UNSPECIFIED RuntimeErrorCode = "SKE_UNSPECIFIED" +) + +// Project defines model for Project. +type Project struct { + ProjectID *string `json:"projectId,omitempty"` + State *ProjectState `json:"state,omitempty"` +} + +// ProjectState defines model for ProjectState. +type ProjectState string + +// RuntimeError defines model for RuntimeError. +type RuntimeError struct { + // Code - Code: `SKE_UNSPECIFIED` + // Message: "An error occurred. Please open a support ticket if this error persists." + // - Code: `SKE_TMP_AUTH_ERROR` + // Message: "Authentication failed. This is a temporary error. Please wait while the system recovers." + // - Code: `SKE_QUOTA_EXCEEDED` + // Message: "Your project's resource quotas are exhausted. Please make sure your quota is sufficient for the ordered cluster." + // - Code: `SKE_ARGUS_INSTANCE_NOT_FOUND` + // Message: "The provided Argus instance could not be found." + // - Code: `SKE_RATE_LIMITS` + // Message: "While provisioning your cluster, request rate limits where incurred. Please wait while the system recovers." + // - Code: `SKE_INFRA_ERROR` + // Message: "An error occurred with the underlying infrastructure. Please open a support ticket if this error persists." + // - Code: `SKE_REMAINING_RESOURCES` + // Message: "There are remaining Kubernetes resources in your cluster that prevent deletion. Please make sure to remove them." + // - Code: `SKE_CONFIGURATION_PROBLEM` + // Message: "A configuration error occurred. Please open a support ticket if this error persists." + // - Code: `SKE_UNREADY_NODES` + // Message: "Not all worker nodes are ready. Please open a support ticket if this error persists." + // - Code: `SKE_API_SERVER_ERROR` + // Message: "The Kubernetes API server is not reporting readiness. Please open a support ticket if this error persists." + Code *RuntimeErrorCode `json:"code,omitempty"` + Details *string `json:"details,omitempty"` + Message *string `json:"message,omitempty"` +} + +// RuntimeErrorCode - Code: `SKE_UNSPECIFIED` +// +// Message: "An error occurred. Please open a support ticket if this error persists." +// - Code: `SKE_TMP_AUTH_ERROR` +// Message: "Authentication failed. This is a temporary error. Please wait while the system recovers." +// - Code: `SKE_QUOTA_EXCEEDED` +// Message: "Your project's resource quotas are exhausted. Please make sure your quota is sufficient for the ordered cluster." +// - Code: `SKE_ARGUS_INSTANCE_NOT_FOUND` +// Message: "The provided Argus instance could not be found." +// - Code: `SKE_RATE_LIMITS` +// Message: "While provisioning your cluster, request rate limits where incurred. Please wait while the system recovers." +// - Code: `SKE_INFRA_ERROR` +// Message: "An error occurred with the underlying infrastructure. Please open a support ticket if this error persists." +// - Code: `SKE_REMAINING_RESOURCES` +// Message: "There are remaining Kubernetes resources in your cluster that prevent deletion. Please make sure to remove them." +// - Code: `SKE_CONFIGURATION_PROBLEM` +// Message: "A configuration error occurred. Please open a support ticket if this error persists." +// - Code: `SKE_UNREADY_NODES` +// Message: "Not all worker nodes are ready. Please open a support ticket if this error persists." +// - Code: `SKE_API_SERVER_ERROR` +// Message: "The Kubernetes API server is not reporting readiness. Please open a support ticket if this error persists." +type RuntimeErrorCode string + +// RequestEditorFn is the function signature for the RequestEditor callback function +type RequestEditorFn func(ctx context.Context, req *http.Request) error + +// Client which conforms to the OpenAPI3 specification for this service. +type Client struct { + // The endpoint of the server conforming to this interface, with scheme, + // https://api.deepmap.com for example. This can contain a path relative + // to the server, such as https://api.deepmap.com/dev-test, and all the + // paths in the swagger spec will be appended to the server. + Server string + + // Doer for performing requests, typically a *http.Client with any + // customized settings, such as certificate chains. + Client contracts.BaseClientInterface +} + +// NewRawClient Creates a new Client, with reasonable defaults +func NewRawClient(server string, httpClient contracts.BaseClientInterface) *Client { + // create a client with sane default values + client := Client{ + Server: server, + Client: httpClient, + } + return &client +} + +// The interface specification for the client above. +type rawClientInterface interface { + // Delete request + DeleteRaw(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // Get request + GetRaw(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // Create request + CreateRaw(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*http.Response, error) +} + +func (c *Client) DeleteRaw(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewDeleteRequest(ctx, c.Server, projectID) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetRaw(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetRequest(ctx, c.Server, projectID) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) CreateRaw(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateRequest(ctx, c.Server, projectID) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +// NewDeleteRequest generates requests for Delete +func NewDeleteRequest(ctx context.Context, server string, projectID string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewGetRequest generates requests for Get +func NewGetRequest(ctx context.Context, server string, projectID string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewCreateRequest generates requests for Create +func NewCreateRequest(ctx context.Context, server string, projectID string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/projects/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "PUT", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { + for _, r := range additionalEditors { + if err := r(ctx, req); err != nil { + return err + } + } + return nil +} + +// ClientWithResponses builds on rawClientInterface to offer response payloads +type ClientWithResponses struct { + rawClientInterface +} + +// NewClient creates a new ClientWithResponses, which wraps +// Client with return type handling +func NewClient(server string, httpClient contracts.BaseClientInterface) *ClientWithResponses { + return &ClientWithResponses{NewRawClient(server, httpClient)} +} + +// ClientWithResponsesInterface is the interface specification for the client with responses above. +type ClientWithResponsesInterface interface { + // Delete request + Delete(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*DeleteResponse, error) + + // Get request + Get(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*GetResponse, error) + + // Create request + Create(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*CreateResponse, error) +} + +type DeleteResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *map[string]interface{} + JSON202 *map[string]interface{} + JSON400 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r DeleteResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r DeleteResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Project + JSON404 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r GetResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type CreateResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Project + JSON400 *map[string]interface{} + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r CreateResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r CreateResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// Delete request returning *DeleteResponse +func (c *ClientWithResponses) Delete(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*DeleteResponse, error) { + rsp, err := c.DeleteRaw(ctx, projectID, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseDeleteResponse(rsp) +} + +// Get request returning *GetResponse +func (c *ClientWithResponses) Get(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*GetResponse, error) { + rsp, err := c.GetRaw(ctx, projectID, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseGetResponse(rsp) +} + +// Create request returning *CreateResponse +func (c *ClientWithResponses) Create(ctx context.Context, projectID string, reqEditors ...RequestEditorFn) (*CreateResponse, error) { + rsp, err := c.CreateRaw(ctx, projectID, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseCreateResponse(rsp) +} + +// ParseDeleteResponse parses an HTTP response from a Delete call +func (c *ClientWithResponses) ParseDeleteResponse(rsp *http.Response) (*DeleteResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &DeleteResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 202: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON202 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseGetResponse parses an HTTP response from a Get call +func (c *ClientWithResponses) ParseGetResponse(rsp *http.Response) (*GetResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Project + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON404 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} + +// ParseCreateResponse parses an HTTP response from a Create call +func (c *ClientWithResponses) ParseCreateResponse(rsp *http.Response) (*CreateResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &CreateResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Project + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} diff --git a/pkg/services/kubernetes/v1.1/project/wait.go b/pkg/services/kubernetes/v1.1/project/wait.go new file mode 100644 index 00000000..c6c8144c --- /dev/null +++ b/pkg/services/kubernetes/v1.1/project/wait.go @@ -0,0 +1,59 @@ +package project + +import ( + "context" + "fmt" + "net/http" + "strings" + + "github.com/SchwarzIT/community-stackit-go-client/pkg/wait" + "github.com/pkg/errors" +) + +func (*CreateResponse) WaitHandler(ctx context.Context, c *ClientWithResponses, projectID string) *wait.Handler { + return wait.New(func() (res interface{}, done bool, err error) { + + resp, err := c.Get(ctx, projectID) + if err != nil { + return nil, false, errors.Wrap(err, "failed during create request preparation") + } + if resp.Error != nil { + if strings.Contains(resp.Error.Error(), "project has no assigned namespace") { + return nil, false, nil + } + return nil, false, err + } + + switch *resp.JSON200.State { + case STATE_FAILED: + fallthrough + case STATE_DELETING: + return nil, false, fmt.Errorf("received state: %s for project ID: %s", + *resp.JSON200.State, + *resp.JSON200.ProjectID, + ) + case STATE_CREATED: + return nil, true, nil + } + return nil, false, nil + }) +} + +func (*DeleteResponse) WaitHandler(ctx context.Context, c *ClientWithResponses, projectID string) *wait.Handler { + return wait.New(func() (res interface{}, done bool, err error) { + resp, err := c.Get(ctx, projectID) + if err != nil { + if strings.Contains(err.Error(), http.StatusText(http.StatusNotFound)) { + return nil, true, nil + } + return nil, false, errors.Wrap(err, "failed during delete request preparation") + } + if resp.Error != nil { + if strings.Contains(resp.Error.Error(), http.StatusText(http.StatusNotFound)) { + return nil, true, nil + } + return nil, false, err + } + return nil, false, nil + }) +} diff --git a/pkg/services/kubernetes/v1.1/provider-options/provider-options.go b/pkg/services/kubernetes/v1.1/provider-options/provider-options.go new file mode 100644 index 00000000..9d0bbbde --- /dev/null +++ b/pkg/services/kubernetes/v1.1/provider-options/provider-options.go @@ -0,0 +1,313 @@ +// Package provideroptions provides primitives to interact with the openapi HTTP API. +// +// Code generated by github.com/do87/stackit-client-generator version v0.0.2 DO NOT EDIT. +package provideroptions + +import ( + "context" + "encoding/json" + "fmt" + "io" + "net/http" + "net/url" + "strings" + + "github.com/pkg/errors" + + contracts "github.com/SchwarzIT/community-stackit-go-client/pkg/contracts" + "github.com/SchwarzIT/community-stackit-go-client/pkg/validate" +) + +const ( + BearerAuthScopes = "bearerAuth.Scopes" +) + +// Defines values for CRIName. +const ( + CONTAINERD CRIName = "containerd" + DOCKER CRIName = "docker" +) + +// Defines values for RuntimeErrorCode. +const ( + SKE_API_SERVER_ERROR RuntimeErrorCode = "SKE_API_SERVER_ERROR" + SKE_ARGUS_INSTANCE_NOT_FOUND RuntimeErrorCode = "SKE_ARGUS_INSTANCE_NOT_FOUND" + SKE_CONFIGURATION_PROBLEM RuntimeErrorCode = "SKE_CONFIGURATION_PROBLEM" + SKE_INFRA_ERROR RuntimeErrorCode = "SKE_INFRA_ERROR" + SKE_QUOTA_EXCEEDED RuntimeErrorCode = "SKE_QUOTA_EXCEEDED" + SKE_RATE_LIMITS RuntimeErrorCode = "SKE_RATE_LIMITS" + SKE_REMAINING_RESOURCES RuntimeErrorCode = "SKE_REMAINING_RESOURCES" + SKE_TMP_AUTH_ERROR RuntimeErrorCode = "SKE_TMP_AUTH_ERROR" + SKE_UNREADY_NODES RuntimeErrorCode = "SKE_UNREADY_NODES" + SKE_UNSPECIFIED RuntimeErrorCode = "SKE_UNSPECIFIED" +) + +// AvailabilityZone defines model for AvailabilityZone. +type AvailabilityZone struct { + Name *string `json:"name,omitempty"` +} + +// CRI defines model for CRI. +type CRI struct { + Name *CRIName `json:"name,omitempty"` +} + +// CRIName defines model for CRI.Name. +type CRIName string + +// KubernetesVersion defines model for KubernetesVersion. +type KubernetesVersion struct { + ExpirationDate *string `json:"expirationDate,omitempty"` + FeatureGates *map[string]string `json:"featureGates,omitempty"` + State *string `json:"state,omitempty"` + Version *string `json:"version,omitempty"` +} + +// MachineImage defines model for MachineImage. +type MachineImage struct { + Name *string `json:"name,omitempty"` + Versions *[]MachineImageVersion `json:"versions,omitempty"` +} + +// MachineImageVersion defines model for MachineImageVersion. +type MachineImageVersion struct { + CRI *[]CRI `json:"cri,omitempty"` + ExpirationDate *string `json:"expirationDate,omitempty"` + State *string `json:"state,omitempty"` + Version *string `json:"version,omitempty"` +} + +// MachineType defines model for MachineType. +type MachineType struct { + CPU *int `json:"cpu,omitempty"` + Memory *int `json:"memory,omitempty"` + Name *string `json:"name,omitempty"` +} + +// ProviderOptions defines model for ProviderOptions. +type ProviderOptions struct { + AvailabilityZones *[]AvailabilityZone `json:"availabilityZones,omitempty"` + KubernetesVersions *[]KubernetesVersion `json:"kubernetesVersions,omitempty"` + MachineImages *[]MachineImage `json:"machineImages,omitempty"` + MachineTypes *[]MachineType `json:"machineTypes,omitempty"` + VolumeTypes *[]VolumeType `json:"volumeTypes,omitempty"` +} + +// RuntimeError defines model for RuntimeError. +type RuntimeError struct { + // Code - Code: `SKE_UNSPECIFIED` + // Message: "An error occurred. Please open a support ticket if this error persists." + // - Code: `SKE_TMP_AUTH_ERROR` + // Message: "Authentication failed. This is a temporary error. Please wait while the system recovers." + // - Code: `SKE_QUOTA_EXCEEDED` + // Message: "Your project's resource quotas are exhausted. Please make sure your quota is sufficient for the ordered cluster." + // - Code: `SKE_ARGUS_INSTANCE_NOT_FOUND` + // Message: "The provided Argus instance could not be found." + // - Code: `SKE_RATE_LIMITS` + // Message: "While provisioning your cluster, request rate limits where incurred. Please wait while the system recovers." + // - Code: `SKE_INFRA_ERROR` + // Message: "An error occurred with the underlying infrastructure. Please open a support ticket if this error persists." + // - Code: `SKE_REMAINING_RESOURCES` + // Message: "There are remaining Kubernetes resources in your cluster that prevent deletion. Please make sure to remove them." + // - Code: `SKE_CONFIGURATION_PROBLEM` + // Message: "A configuration error occurred. Please open a support ticket if this error persists." + // - Code: `SKE_UNREADY_NODES` + // Message: "Not all worker nodes are ready. Please open a support ticket if this error persists." + // - Code: `SKE_API_SERVER_ERROR` + // Message: "The Kubernetes API server is not reporting readiness. Please open a support ticket if this error persists." + Code *RuntimeErrorCode `json:"code,omitempty"` + Details *string `json:"details,omitempty"` + Message *string `json:"message,omitempty"` +} + +// RuntimeErrorCode - Code: `SKE_UNSPECIFIED` +// +// Message: "An error occurred. Please open a support ticket if this error persists." +// - Code: `SKE_TMP_AUTH_ERROR` +// Message: "Authentication failed. This is a temporary error. Please wait while the system recovers." +// - Code: `SKE_QUOTA_EXCEEDED` +// Message: "Your project's resource quotas are exhausted. Please make sure your quota is sufficient for the ordered cluster." +// - Code: `SKE_ARGUS_INSTANCE_NOT_FOUND` +// Message: "The provided Argus instance could not be found." +// - Code: `SKE_RATE_LIMITS` +// Message: "While provisioning your cluster, request rate limits where incurred. Please wait while the system recovers." +// - Code: `SKE_INFRA_ERROR` +// Message: "An error occurred with the underlying infrastructure. Please open a support ticket if this error persists." +// - Code: `SKE_REMAINING_RESOURCES` +// Message: "There are remaining Kubernetes resources in your cluster that prevent deletion. Please make sure to remove them." +// - Code: `SKE_CONFIGURATION_PROBLEM` +// Message: "A configuration error occurred. Please open a support ticket if this error persists." +// - Code: `SKE_UNREADY_NODES` +// Message: "Not all worker nodes are ready. Please open a support ticket if this error persists." +// - Code: `SKE_API_SERVER_ERROR` +// Message: "The Kubernetes API server is not reporting readiness. Please open a support ticket if this error persists." +type RuntimeErrorCode string + +// VolumeType defines model for VolumeType. +type VolumeType struct { + Name *string `json:"name,omitempty"` +} + +// RequestEditorFn is the function signature for the RequestEditor callback function +type RequestEditorFn func(ctx context.Context, req *http.Request) error + +// Client which conforms to the OpenAPI3 specification for this service. +type Client struct { + // The endpoint of the server conforming to this interface, with scheme, + // https://api.deepmap.com for example. This can contain a path relative + // to the server, such as https://api.deepmap.com/dev-test, and all the + // paths in the swagger spec will be appended to the server. + Server string + + // Doer for performing requests, typically a *http.Client with any + // customized settings, such as certificate chains. + Client contracts.BaseClientInterface +} + +// NewRawClient Creates a new Client, with reasonable defaults +func NewRawClient(server string, httpClient contracts.BaseClientInterface) *Client { + // create a client with sane default values + client := Client{ + Server: server, + Client: httpClient, + } + return &client +} + +// The interface specification for the client above. +type rawClientInterface interface { + // List request + ListRaw(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) +} + +func (c *Client) ListRaw(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewListRequest(ctx, c.Server) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +// NewListRequest generates requests for List +func NewListRequest(ctx context.Context, server string) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/provider-options") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequestWithContext(ctx, "GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error { + for _, r := range additionalEditors { + if err := r(ctx, req); err != nil { + return err + } + } + return nil +} + +// ClientWithResponses builds on rawClientInterface to offer response payloads +type ClientWithResponses struct { + rawClientInterface +} + +// NewClient creates a new ClientWithResponses, which wraps +// Client with return type handling +func NewClient(server string, httpClient contracts.BaseClientInterface) *ClientWithResponses { + return &ClientWithResponses{NewRawClient(server, httpClient)} +} + +// ClientWithResponsesInterface is the interface specification for the client with responses above. +type ClientWithResponsesInterface interface { + // List request + List(ctx context.Context, reqEditors ...RequestEditorFn) (*ListResponse, error) +} + +type ListResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *ProviderOptions + JSONDefault *RuntimeError + Error error // Aggregated error +} + +// Status returns HTTPResponse.Status +func (r ListResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r ListResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// List request returning *ListResponse +func (c *ClientWithResponses) List(ctx context.Context, reqEditors ...RequestEditorFn) (*ListResponse, error) { + rsp, err := c.ListRaw(ctx, reqEditors...) + if err != nil { + return nil, err + } + return c.ParseListResponse(rsp) +} + +// ParseListResponse parses an HTTP response from a List call +func (c *ClientWithResponses) ParseListResponse(rsp *http.Response) (*ListResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &ListResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + response.Error = validate.DefaultResponseErrorHandler(rsp) + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest ProviderOptions + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest RuntimeError + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, errors.Wrap(err, fmt.Sprintf("body was: %s", string(bodyBytes))) + } + response.JSONDefault = &dest + + } + + return response, validate.ResponseObject(response) +} diff --git a/pkg/services/kubernetes/v1.1/service.go b/pkg/services/kubernetes/v1.1/service.go new file mode 100644 index 00000000..2ce48189 --- /dev/null +++ b/pkg/services/kubernetes/v1.1/service.go @@ -0,0 +1,16 @@ +package kubernetes + +import ( + "github.com/SchwarzIT/community-stackit-go-client/pkg/baseurl" + "github.com/SchwarzIT/community-stackit-go-client/pkg/contracts" +) + +var BaseURLs = baseurl.New( + "kubernetes", + "https://ske.api.eu01.stackit.cloud/", +) + +func NewService(c contracts.BaseClientInterface) *ClientWithResponses { + nc, _ := NewClient(BaseURLs.Get(), WithHTTPClient(c)) + return nc +}