diff --git a/internal/client/clusterclass/clusterclass_resource.go b/internal/client/clusterclass/clusterclass_resource.go new file mode 100644 index 000000000..37b2bae5c --- /dev/null +++ b/internal/client/clusterclass/clusterclass_resource.go @@ -0,0 +1,58 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package clusterclassclient + +import ( + "net/url" + + "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/transport" + "github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper" + clusterclassmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/clusterclass" +) + +const ( + apiVersionAndGroup = "/v1alpha1/managementclusters" + provisioners = "provisioners" + clusterClasses = "clusterclasses" + nameQueryParamKey = "name" +) + +// New creates a new tanzu kubernetes cluster resource service API client. +func New(transport *transport.Client) ClientService { + return &Client{Client: transport} +} + +/* +Client for tanzu kubernetes cluster resource service API. +*/ +type Client struct { + *transport.Client +} + +// ClientService is the interface for Client methods. +type ClientService interface { + ClusterClassResourceServiceGet(fn *clusterclassmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassFullName) (*clusterclassmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassListClusterClassesResponse, error) +} + +/* +ClusterClassResourceServiceGet gets or lists cluster classes. +*/ +func (c *Client) ClusterClassResourceServiceGet(fn *clusterclassmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassFullName) (*clusterclassmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassListClusterClassesResponse, error) { + response := &clusterclassmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassListClusterClassesResponse{} + requestURL := helper.ConstructRequestURL(apiVersionAndGroup, fn.ManagementClusterName, provisioners, fn.ProvisionerName, clusterClasses) + + if fn.Name != "" { + queryParams := url.Values{ + nameQueryParamKey: {fn.Name}, + } + + requestURL = requestURL.AppendQueryParams(queryParams) + } + + err := c.Get(requestURL.String(), response) + + return response, err +} diff --git a/internal/client/http_client.go b/internal/client/http_client.go index 92eb07d1a..fbf60dba2 100644 --- a/internal/client/http_client.go +++ b/internal/client/http_client.go @@ -20,6 +20,7 @@ import ( packageclusterclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/cluster/package" policyclusterclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/cluster/policy" sourcesecretclusterclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/cluster/sourcesecret" + clusterclassclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/clusterclass" clustergroupclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/clustergroup" continuousdeliveryclustergroupclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/clustergroup/continuousdelivery" gitrepositoryclustergroupclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/clustergroup/gitrepository" @@ -39,6 +40,7 @@ import ( iamorganizationclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/organization/iam_policy" policyorganizationclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/organization/policy" "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/proxy" + tanzukubernetesclusterclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/tanzukubernetescluster" tanzupackageclusterclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/tanzupackage" pkginstallclusterclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/tanzupackageinstall" pkgrepositoryclusterclient "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/tanzupackagerepository" @@ -112,6 +114,8 @@ func newHTTPClient(httpClient *transport.Client) *TanzuMissionControl { ClusterTanzuPackageService: tanzupackageclusterclient.New(httpClient), TanzupackageResourceService: packageclusterclient.New(httpClient), PackageInstallResourceService: pkginstallclusterclient.New(httpClient), + ClusterClassResourceService: clusterclassclient.New(httpClient), + TanzuKubernetesClusterResourceService: tanzukubernetesclusterclient.New(httpClient), } } @@ -154,4 +158,6 @@ type TanzuMissionControl struct { ClusterTanzuPackageService tanzupackageclusterclient.ClientService TanzupackageResourceService packageclusterclient.ClientService PackageInstallResourceService pkginstallclusterclient.ClientService + ClusterClassResourceService clusterclassclient.ClientService + TanzuKubernetesClusterResourceService tanzukubernetesclusterclient.ClientService } diff --git a/internal/client/tanzukubernetescluster/tanzukubernetescluster_resource.go b/internal/client/tanzukubernetescluster/tanzukubernetescluster_resource.go new file mode 100644 index 000000000..182c1d39f --- /dev/null +++ b/internal/client/tanzukubernetescluster/tanzukubernetescluster_resource.go @@ -0,0 +1,93 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tanzukubernetesclusterclient + +import ( + "net/url" + + "github.com/vmware/terraform-provider-tanzu-mission-control/internal/client/transport" + "github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper" + + tkcmodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/tanzukubernetescluster" +) + +const ( + apiVersionAndGroup = "/v1alpha1/managementclusters" + provisioners = "provisioners" + tanzukubernetesclusters = "tanzukubernetesclusters" + forceQueryParamKey = "force" +) + +// New creates a new tanzu kubernetes cluster resource service API client. +func New(transport *transport.Client) ClientService { + return &Client{Client: transport} +} + +/* +Client for tanzu kubernetes cluster resource service API. +*/ +type Client struct { + *transport.Client +} + +// ClientService is the interface for Client methods. +type ClientService interface { + TanzuKubernetesClusterResourceServiceCreate(req *tkcmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCreateTanzuKubernetesClusterRequest) (*tkcmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCreateTanzuKubernetesClusterResponse, error) + + TanzuKubernetesClusterResourceServiceDelete(fn *tkcmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterFullName, force bool) error + + TanzuKubernetesClusterResourceServiceGet(fn *tkcmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterFullName) (*tkcmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterGetTanzuKubernetesClusterResponse, error) + + TanzuKubernetesClusterResourceServiceUpdate(req *tkcmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCreateTanzuKubernetesClusterRequest) (*tkcmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCreateTanzuKubernetesClusterResponse, error) +} + +/* +TanzuKubernetesClusterResourceServiceCreate creates a tanzu kubernetes cluster. +*/ +func (c *Client) TanzuKubernetesClusterResourceServiceCreate(request *tkcmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCreateTanzuKubernetesClusterRequest) (*tkcmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCreateTanzuKubernetesClusterResponse, error) { + response := &tkcmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCreateTanzuKubernetesClusterResponse{} + requestURL := helper.ConstructRequestURL(apiVersionAndGroup, request.TanzuKubernetesCluster.FullName.ManagementClusterName, provisioners, + request.TanzuKubernetesCluster.FullName.ProvisionerName, tanzukubernetesclusters) + err := c.Create(requestURL.String(), request, response) + + return response, err +} + +/* +TanzuKubernetesClusterResourceServiceDelete deletes a tanzu kubernetes cluster. +*/ +func (c *Client) TanzuKubernetesClusterResourceServiceDelete(fn *tkcmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterFullName, force bool) error { + queryParams := url.Values{ + forceQueryParamKey: {helper.ConvertToString(force, "")}, + } + + requestURL := helper.ConstructRequestURL(apiVersionAndGroup, fn.ManagementClusterName, provisioners, fn.ProvisionerName, tanzukubernetesclusters, fn.Name).AppendQueryParams(queryParams) + err := c.Delete(requestURL.String()) + + return err +} + +/* +TanzuKubernetesClusterResourceServiceGet gets a tanzu kubernetes cluster. +*/ +func (c *Client) TanzuKubernetesClusterResourceServiceGet(fn *tkcmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterFullName) (*tkcmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterGetTanzuKubernetesClusterResponse, error) { + response := &tkcmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterGetTanzuKubernetesClusterResponse{} + requestURL := helper.ConstructRequestURL(apiVersionAndGroup, fn.ManagementClusterName, provisioners, fn.ProvisionerName, tanzukubernetesclusters, fn.Name) + err := c.Get(requestURL.String(), response) + + return response, err +} + +/* +TanzuKubernetesClusterResourceServiceUpdate updates overwrite a tanzu kubernetes cluster. +*/ +func (c *Client) TanzuKubernetesClusterResourceServiceUpdate(request *tkcmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCreateTanzuKubernetesClusterRequest) (*tkcmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCreateTanzuKubernetesClusterResponse, error) { + response := &tkcmodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCreateTanzuKubernetesClusterResponse{} + requestURL := helper.ConstructRequestURL(apiVersionAndGroup, request.TanzuKubernetesCluster.FullName.ManagementClusterName, provisioners, request.TanzuKubernetesCluster.FullName.ProvisionerName, tanzukubernetesclusters, request.TanzuKubernetesCluster.FullName.Name) + err := c.Update(requestURL.String(), request, response) + + return response, err +} diff --git a/internal/helper/converter/map_types.go b/internal/helper/converter/map_types.go index 1452cb32a..61585122c 100644 --- a/internal/helper/converter/map_types.go +++ b/internal/helper/converter/map_types.go @@ -13,10 +13,20 @@ import ( // BlockToStruct Converts a Terraform Block to a Swagger Struct (1:1). type BlockToStruct map[string]interface{} -// BlockToStructSlice Converts a Terraform Block to a Slice of Swagger Structs (1:N). +// BlockToStructSliceField Converts a Terraform Block to a Slice of Swagger Structs (1:N). +type BlockToStructSliceField struct { + Field string + Mapping BlockToStructSlice +} + type BlockToStructSlice []*BlockToStruct -// BlockSliceToStructSlice Converts a Terraform Block Slice to a Slice of Swagger Structs (N:N). +// BlockSliceToStructSliceField Converts a Terraform Block to a Slice of Swagger Structs (N:N). +type BlockSliceToStructSliceField struct { + Field string + Mapping BlockToStructSlice +} + type BlockSliceToStructSlice []*BlockToStruct // Map Converts a Terraform Block/Map to Swagger Struct/Map. diff --git a/internal/models/clusterclass/clusterclass.go b/internal/models/clusterclass/clusterclass.go new file mode 100644 index 000000000..9417a00dd --- /dev/null +++ b/internal/models/clusterclass/clusterclass.go @@ -0,0 +1,50 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package clusterclass + +import ( + "github.com/go-openapi/swag" + objectmetamodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/objectmeta" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassClusterClass A Kubernetes Cluster Class. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.clusterclass.ClusterClass +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassClusterClass struct { + + // Full name for the cluster class. + FullName *VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassFullName `json:"fullName,omitempty"` + + // Metadata for the cluster class object. + Meta *objectmetamodel.VmwareTanzuCoreV1alpha1ObjectMeta `json:"meta,omitempty"` + + // Spec for the cluster class. + Spec *VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassSpec `json:"spec,omitempty"` + + // Status of the cluster class. + Status *VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassStatus `json:"status,omitempty"` + + // Metadata describing the type of the resource. + Type *objectmetamodel.VmwareTanzuCoreV1alpha1ObjectType `json:"type,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassClusterClass) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassClusterClass) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassClusterClass + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/internal/models/clusterclass/fullname.go b/internal/models/clusterclass/fullname.go new file mode 100644 index 000000000..2331d4a48 --- /dev/null +++ b/internal/models/clusterclass/fullname.go @@ -0,0 +1,47 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package clusterclass + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassFullName Full name of the cluster class. This includes the object name along +// with any parents or further identifiers. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.clusterclass.FullName +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassFullName struct { + + // Name of the management cluster. + ManagementClusterName string `json:"managementClusterName,omitempty"` + + // Name of this cluster class. + Name string `json:"name,omitempty"` + + // ID of Organization. + OrgID string `json:"orgId,omitempty"` + + // Provisioner of the cluster class. + ProvisionerName string `json:"provisionerName,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassFullName) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassFullName) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassFullName + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/internal/models/clusterclass/request.go b/internal/models/clusterclass/request.go new file mode 100644 index 000000000..3a9feefed --- /dev/null +++ b/internal/models/clusterclass/request.go @@ -0,0 +1,40 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package clusterclass + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassListClusterClassesResponse Response from listing ClusterClasses. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.clusterclass.ListClusterClassesResponse. +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassListClusterClassesResponse struct { + + // List of clusterclasses. + ClusterClasses []*VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassClusterClass `json:"clusterClasses"` + + // Total count. + TotalCount string `json:"totalCount,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassListClusterClassesResponse) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassListClusterClassesResponse) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassListClusterClassesResponse + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/internal/models/clusterclass/schema.go b/internal/models/clusterclass/schema.go new file mode 100644 index 000000000..fded9a6bc --- /dev/null +++ b/internal/models/clusterclass/schema.go @@ -0,0 +1,66 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package clusterclass + +import ( + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassVariableSchema VariableSchema defines the schema of a variable. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.clusterclass.VariableSchema +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassVariableSchema struct { + + // Template values in OpenAPI V3 schema format. + Template *K8sIoApimachineryPkgRuntimeRawExtension `json:"template,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassVariableSchema) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassVariableSchema) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassVariableSchema + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} + +// swagger:model k8s.io.apimachinery.pkg.runtime.RawExtension +type K8sIoApimachineryPkgRuntimeRawExtension struct { + + // Raw is the underlying serialization of this object. + Raw strfmt.Base64 `json:"raw,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *K8sIoApimachineryPkgRuntimeRawExtension) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *K8sIoApimachineryPkgRuntimeRawExtension) UnmarshalBinary(b []byte) error { + var res K8sIoApimachineryPkgRuntimeRawExtension + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/clusterclass/spec.go b/internal/models/clusterclass/spec.go new file mode 100644 index 000000000..0c29b1c6b --- /dev/null +++ b/internal/models/clusterclass/spec.go @@ -0,0 +1,42 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package clusterclass + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassSpec Spec of the cluster class. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.clusterclass.Spec +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassSpec struct { + + // Variables defines the variables which can be configured + // in the Cluster topology and are then used in patches. + Variables []*VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassClusterClassVariable `json:"variables"` + + // Workers classes is a collection of node types which can be used to create + // the worker nodes of the cluster. + WorkersClasses []string `json:"workersClasses"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassSpec) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassSpec) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassSpec + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/internal/models/clusterclass/status.go b/internal/models/clusterclass/status.go new file mode 100644 index 000000000..8f09661e9 --- /dev/null +++ b/internal/models/clusterclass/status.go @@ -0,0 +1,42 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package clusterclass + +import ( + "github.com/go-openapi/swag" + + statusmodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/status" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassStatus Status of the cluster class. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.clusterclass.Status +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassStatus struct { + + // Conditions of the resource. + Conditions map[string]statusmodel.VmwareTanzuCoreV1alpha1StatusCondition `json:"conditions,omitempty"` + + // Schema of cluster class variables for UI to render. + VariablesSchema *K8sIoApimachineryPkgRuntimeRawExtension `json:"variablesSchema,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassStatus) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassStatus) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassStatus + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/internal/models/clusterclass/variables.go b/internal/models/clusterclass/variables.go new file mode 100644 index 000000000..adec88ce6 --- /dev/null +++ b/internal/models/clusterclass/variables.go @@ -0,0 +1,43 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package clusterclass + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassClusterClassVariable ClusterClassVariable defines a variable which can be configured in the Cluster topology. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.clusterclass.ClusterClassVariable +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassClusterClassVariable struct { + + // Name of the cluster class variable. + Name string `json:"name,omitempty"` + + // Required specifies if the variable is required. + Required bool `json:"required,omitempty"` + + // Schema defines the schema of the variable. + Schema *VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassVariableSchema `json:"schema,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassClusterClassVariable) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassClusterClassVariable) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerClusterclassClusterClassVariable + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/internal/models/tanzukubernetescluster/common/cluster_metadata.go b/internal/models/tanzukubernetescluster/common/cluster_metadata.go new file mode 100644 index 000000000..ba8de38a5 --- /dev/null +++ b/internal/models/tanzukubernetescluster/common/cluster_metadata.go @@ -0,0 +1,43 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkccommon + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterMetadata The labels and annotations configurations. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.common.cluster.Metadata +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterMetadata struct { + + // The annotations configuration. + Annotations map[string]string `json:"annotations,omitempty"` + + // The labels configuration. + Labels map[string]string `json:"labels,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterMetadata) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterMetadata) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterMetadata + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/common/cluster_os_image.go b/internal/models/tanzukubernetescluster/common/cluster_os_image.go new file mode 100644 index 000000000..41c370ca3 --- /dev/null +++ b/internal/models/tanzukubernetescluster/common/cluster_os_image.go @@ -0,0 +1,46 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkccommon + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterOSImage The OS image configuration. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.common.cluster.OSImage +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterOSImage struct { + + // The arch of the OS image. + Arch string `json:"arch,omitempty"` + + // The name of the OS image. + Name string `json:"name,omitempty"` + + // The version of the OS image. + Version string `json:"version,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterOSImage) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterOSImage) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterOSImage + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/common/cluster_variable.go b/internal/models/tanzukubernetescluster/common/cluster_variable.go new file mode 100644 index 000000000..8369229a7 --- /dev/null +++ b/internal/models/tanzukubernetescluster/common/cluster_variable.go @@ -0,0 +1,43 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkccommon + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterClusterVariable The TKG cluster variable configuration. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.common.cluster.ClusterVariable +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterClusterVariable struct { + + // Name of the variable. + Name string `json:"name,omitempty"` + + // Value of the variable. + Value interface{} `json:"value,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterClusterVariable) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterClusterVariable) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterClusterVariable + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/control_plane.go b/internal/models/tanzukubernetescluster/control_plane.go new file mode 100644 index 000000000..3457832fb --- /dev/null +++ b/internal/models/tanzukubernetescluster/control_plane.go @@ -0,0 +1,48 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcmodels + +import ( + "github.com/go-openapi/swag" + + tkccommon "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/tanzukubernetescluster/common" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterControlPlane The cluster specific control plane configuration. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.ControlPlane +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterControlPlane struct { + + // The metadata of the control plane. + Metadata *tkccommon.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterMetadata `json:"metadata,omitempty"` + + // The OS image of the control plane. + OsImage *tkccommon.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterOSImage `json:"osImage,omitempty"` + + // The replicas of the control plane. + Replicas int32 `json:"replicas,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterControlPlane) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterControlPlane) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterControlPlane + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/core_addon.go b/internal/models/tanzukubernetescluster/core_addon.go new file mode 100644 index 000000000..284e9f881 --- /dev/null +++ b/internal/models/tanzukubernetescluster/core_addon.go @@ -0,0 +1,43 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcmodels + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCoreAddon The core addon. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.CoreAddon +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCoreAddon struct { + + // Provider of core addon, e.g. 'antrea', 'calico'. + Provider string `json:"provider,omitempty"` + + // Type of core addon, e.g. 'cni'. + Type string `json:"type,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCoreAddon) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCoreAddon) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCoreAddon + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/fullname.go b/internal/models/tanzukubernetescluster/fullname.go new file mode 100644 index 000000000..283fc6d62 --- /dev/null +++ b/internal/models/tanzukubernetescluster/fullname.go @@ -0,0 +1,50 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcmodels + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterFullName Full name of the cluster. This includes the object name along +// with any parents or further identifiers. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.FullName +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterFullName struct { + + // Name of the management cluster. + ManagementClusterName string `json:"managementClusterName,omitempty"` + + // Name of this cluster. + Name string `json:"name,omitempty"` + + // ID of Organization. + OrgID string `json:"orgId,omitempty"` + + // Provisioner of the cluster. + ProvisionerName string `json:"provisionerName,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterFullName) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterFullName) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterFullName + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/method_create.go b/internal/models/tanzukubernetescluster/method_create.go new file mode 100644 index 000000000..51d8821c1 --- /dev/null +++ b/internal/models/tanzukubernetescluster/method_create.go @@ -0,0 +1,70 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcmodels + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCreateTanzuKubernetesClusterRequest Request to create a TanzuKubernetesCluster. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.CreateTanzuKubernetesClusterRequest +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCreateTanzuKubernetesClusterRequest struct { + + // TanzuKubernetesCluster to create. + TanzuKubernetesCluster *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterTanzuKubernetesCluster `json:"tanzuKubernetesCluster,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCreateTanzuKubernetesClusterRequest) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCreateTanzuKubernetesClusterRequest) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCreateTanzuKubernetesClusterRequest + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCreateTanzuKubernetesClusterResponse Response from creating a TanzuKubernetesCluster. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.CreateTanzuKubernetesClusterResponse +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCreateTanzuKubernetesClusterResponse struct { + + // TanzuKubernetesCluster created. + TanzuKubernetesCluster *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterTanzuKubernetesCluster `json:"tanzuKubernetesCluster,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCreateTanzuKubernetesClusterResponse) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCreateTanzuKubernetesClusterResponse) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCreateTanzuKubernetesClusterResponse + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/method_get.go b/internal/models/tanzukubernetescluster/method_get.go new file mode 100644 index 000000000..070b11f08 --- /dev/null +++ b/internal/models/tanzukubernetescluster/method_get.go @@ -0,0 +1,40 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcmodels + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterGetTanzuKubernetesClusterResponse Response from getting a TanzuKubernetesCluster. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.GetTanzuKubernetesClusterResponse +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterGetTanzuKubernetesClusterResponse struct { + + // TanzuKubernetesCluster returned. + TanzuKubernetesCluster *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterTanzuKubernetesCluster `json:"tanzuKubernetesCluster,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterGetTanzuKubernetesClusterResponse) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterGetTanzuKubernetesClusterResponse) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterGetTanzuKubernetesClusterResponse + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/network_ranges.go b/internal/models/tanzukubernetescluster/network_ranges.go new file mode 100644 index 000000000..174054226 --- /dev/null +++ b/internal/models/tanzukubernetescluster/network_ranges.go @@ -0,0 +1,40 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcmodels + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNetworkRanges NetworkRanges describes a collection of IP addresses as a list of ranges. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.NetworkRanges +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNetworkRanges struct { + + // CIDRBlocks specifies one or more ranges of IP addresses. + CidrBlocks []string `json:"cidrBlocks"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNetworkRanges) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNetworkRanges) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNetworkRanges + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/network_settings.go b/internal/models/tanzukubernetescluster/network_settings.go new file mode 100644 index 000000000..d70f890a7 --- /dev/null +++ b/internal/models/tanzukubernetescluster/network_settings.go @@ -0,0 +1,46 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcmodels + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNetworkSettings Network related settings for the cluster. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.NetworkSettings +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNetworkSettings struct { + + // Pod CIDR for Kubernetes pods defaults to 192.168.0.0/16. + Pods *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNetworkRanges `json:"pods,omitempty"` + + // Domain name for services. + ServiceDomain string `json:"serviceDomain,omitempty"` + + // Service CIDR for kubernetes services defaults to 10.96.0.0/12. + Services *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNetworkRanges `json:"services,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNetworkSettings) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNetworkSettings) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNetworkSettings + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/nodepool/nodepool_definition.go b/internal/models/tanzukubernetescluster/nodepool/nodepool_definition.go new file mode 100644 index 000000000..b9cbe2f85 --- /dev/null +++ b/internal/models/tanzukubernetescluster/nodepool/nodepool_definition.go @@ -0,0 +1,43 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcnodepool + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolDefinition Definition is the definition of nodepool for cluster. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.nodepool.Definition +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolDefinition struct { + + // Info for the nodepool. + Info *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolInfo `json:"info,omitempty"` + + // Spec for the nodepool. + Spec *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolSpec `json:"spec,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolDefinition) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolDefinition) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolDefinition + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/nodepool/nodepool_full_name.go b/internal/models/tanzukubernetescluster/nodepool/nodepool_full_name.go new file mode 100644 index 000000000..d8d7c3bff --- /dev/null +++ b/internal/models/tanzukubernetescluster/nodepool/nodepool_full_name.go @@ -0,0 +1,51 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcnodepool + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolFullName Full name of the nodepool. This includes the object name along with any parents or further identifiers. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.nodepool.FullName +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolFullName struct { + // Name of the management cluster. + ManagementClusterName string `json:"managementClusterName,omitempty"` + + // Name of this nodepool. + Name string `json:"name,omitempty"` + + // ID of Organization. + OrgID string `json:"orgId,omitempty"` + + // Provisioner of the cluster. + ProvisionerName string `json:"provisionerName,omitempty"` + + // Name of the cluster. + TanzuKubernetesClusterName string `json:"tanzuKubernetesClusterName,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolFullName) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolFullName) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolFullName + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/nodepool/nodepool_info.go b/internal/models/tanzukubernetescluster/nodepool/nodepool_info.go new file mode 100644 index 000000000..be549504d --- /dev/null +++ b/internal/models/tanzukubernetescluster/nodepool/nodepool_info.go @@ -0,0 +1,43 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcnodepool + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolInfo Info is the meta information of nodepool for cluster. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.nodepool.Info +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolInfo struct { + + // Description for the nodepool. + Description string `json:"description,omitempty"` + + // Name of the nodepool. + Name string `json:"name,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolInfo) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolInfo) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolInfo + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/nodepool/nodepool_method_create.go b/internal/models/tanzukubernetescluster/nodepool/nodepool_method_create.go new file mode 100644 index 000000000..aeec35ad1 --- /dev/null +++ b/internal/models/tanzukubernetescluster/nodepool/nodepool_method_create.go @@ -0,0 +1,70 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcnodepool + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolAPIRequest Request to create a Nodepool. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.nodepool.CreateNodepoolRequest +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolAPIRequest struct { + + // Nodepool to create/update/get. + Nodepool *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolNodepool `json:"nodepool,omitempty"` +} + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolAPIResponse Response from creating a Nodepool. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.nodepool.CreateNodepoolResponse +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolAPIResponse struct { + + // Nodepool created/updated/fetched. + Nodepool *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolNodepool `json:"nodepool,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolAPIRequest) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolAPIRequest) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolAPIRequest + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolAPIResponse) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolAPIResponse) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolAPIResponse + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/nodepool/nodepool_method_list.go b/internal/models/tanzukubernetescluster/nodepool/nodepool_method_list.go new file mode 100644 index 000000000..a0870c1bb --- /dev/null +++ b/internal/models/tanzukubernetescluster/nodepool/nodepool_method_list.go @@ -0,0 +1,43 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcnodepool + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolListNodepoolsResponse Response from listing Nodepools. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.nodepool.ListNodepoolsResponse +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolListNodepoolsResponse struct { + + // List of nodepools. + Nodepools []*VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolNodepool `json:"nodepools"` + + // Total count. + TotalCount string `json:"totalCount,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolListNodepoolsResponse) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolListNodepoolsResponse) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolListNodepoolsResponse + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/nodepool/nodepool_resource.go b/internal/models/tanzukubernetescluster/nodepool/nodepool_resource.go new file mode 100644 index 000000000..343ef3875 --- /dev/null +++ b/internal/models/tanzukubernetescluster/nodepool/nodepool_resource.go @@ -0,0 +1,53 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcnodepool + +import ( + "github.com/go-openapi/swag" + + objectmetamodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/objectmeta" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolNodepool Nodepool associated with a tanzu Kubernetes cluster. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.nodepool.Nodepool +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolNodepool struct { + // Full name of the nodepool. This includes the object name along with any parents or further identifiers. + FullName *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolFullName `json:"fullName,omitempty"` + + // Holds general shared object metadatas. + Meta *objectmetamodel.VmwareTanzuCoreV1alpha1ObjectMeta `json:"meta,omitempty"` + + // Spec for the cluster nodepool. + Spec *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolSpec `json:"spec,omitempty"` + + // Status of node pool resource. + Status *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatus `json:"status,omitempty"` + + // Holds general type metadatas. + Type *objectmetamodel.VmwareTanzuCoreV1alpha1ObjectType `json:"type,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolNodepool) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolNodepool) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolNodepool + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/nodepool/nodepool_spec.go b/internal/models/tanzukubernetescluster/nodepool/nodepool_spec.go new file mode 100644 index 000000000..f78524702 --- /dev/null +++ b/internal/models/tanzukubernetescluster/nodepool/nodepool_spec.go @@ -0,0 +1,57 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcnodepool + +import ( + "github.com/go-openapi/swag" + + tkccommon "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/tanzukubernetescluster/common" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolSpec Spec for the cluster nodepool. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.nodepool.Spec +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolSpec struct { + + // The name of the machine deployment class used to create the nodepool. + Class string `json:"class,omitempty"` + + // The failure domain the machines will be created in. + FailureDomain string `json:"failureDomain,omitempty"` + + // The metadata of the nodepool. + Metadata *tkccommon.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterMetadata `json:"metadata,omitempty"` + + // The OS image of the nodepool. + OsImage *tkccommon.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterOSImage `json:"osImage,omitempty"` + + // Overrides can be used to override cluster level variables. + Overrides []*tkccommon.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterClusterVariable `json:"overrides"` + + // The replicas of the nodepool. + Replicas int32 `json:"replicas,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolSpec) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolSpec) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolSpec + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/nodepool/nodepool_status.go b/internal/models/tanzukubernetescluster/nodepool/nodepool_status.go new file mode 100644 index 000000000..5c33a6913 --- /dev/null +++ b/internal/models/tanzukubernetescluster/nodepool/nodepool_status.go @@ -0,0 +1,45 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcnodepool + +import ( + "github.com/go-openapi/swag" + + statusmodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/status" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatus Status of node pool resource. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.nodepool.Status + +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatus struct { + // Phase of the nodepool resource. + Phase *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhase `json:"phase,omitempty"` + + // Conditions for the nodepool resource. + Conditions map[string]statusmodel.VmwareTanzuCoreV1alpha1StatusCondition `json:"conditions,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatus) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatus) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatus + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/nodepool/nodepool_status_phase.go b/internal/models/tanzukubernetescluster/nodepool/nodepool_status_phase.go new file mode 100644 index 000000000..5b21644ab --- /dev/null +++ b/internal/models/tanzukubernetescluster/nodepool/nodepool_status_phase.go @@ -0,0 +1,64 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcnodepool + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhase Phase of the nodepool resource. +// +// - PHASE_UNSPECIFIED: Unspecified phase. +// - CREATING: Resource is pending processing. +// - READY: Resource is in ready state. +// - ERROR: Error in processing. +// - DELETING: Resource is being deleted. +// - RESIZING: Resizing state. +// - UPGRADING: An upgrade is in progress. +// - UPGRADE_FAILED: An upgrade has failed. +// - WAITING: The cluster is not created yet. so wait till then. +// - UPDATING: A generic phase for nodepool update. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.nodepool.Status.Phase +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhase string + +func NewVmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhase(value VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhase) *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhase { + return &value +} + +// Pointer returns a pointer to a freshly-allocated VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhase. +func (m VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhase) Pointer() *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhase { + return &m +} + +const ( + + // VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhasePHASEUNSPECIFIED captures enum value "PHASE_UNSPECIFIED". + VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhasePHASEUNSPECIFIED VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhase = "PHASE_UNSPECIFIED" + + // VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhaseCREATING captures enum value "CREATING". + VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhaseCREATING VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhase = "CREATING" + + // VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhaseREADY captures enum value "READY". + VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhaseREADY VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhase = "READY" + + // VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhaseERROR captures enum value "ERROR". + VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhaseERROR VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhase = "ERROR" + + // VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhaseDELETING captures enum value "DELETING". + VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhaseDELETING VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhase = "DELETING" + + // VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhaseRESIZING captures enum value "RESIZING". + VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhaseRESIZING VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhase = "RESIZING" + + // VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhaseUPGRADING captures enum value "UPGRADING". + VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhaseUPGRADING VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhase = "UPGRADING" + + // VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhaseUPGRADEFAILED captures enum value "UPGRADE_FAILED". + VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhaseUPGRADEFAILED VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhase = "UPGRADE_FAILED" + + // VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhaseWAITING captures enum value "WAITING". + VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhaseWAITING VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhase = "WAITING" + + // VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhaseUPDATING captures enum value "UPDATING". + VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhaseUPDATING VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolStatusPhase = "UPDATING" +) diff --git a/internal/models/tanzukubernetescluster/spec.go b/internal/models/tanzukubernetescluster/spec.go new file mode 100644 index 000000000..bd2f05488 --- /dev/null +++ b/internal/models/tanzukubernetescluster/spec.go @@ -0,0 +1,52 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcmodels + +import ( + "github.com/go-openapi/swag" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterSpec Spec of the cluster. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.Spec +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterSpec struct { + + // Name of the cluster group to which this cluster belongs. + ClusterGroupName string `json:"clusterGroupName,omitempty"` + + // Name of the image registry configuration to use. + ImageRegistry string `json:"imageRegistry,omitempty"` + + // Name of the proxy configuration to use. + ProxyName string `json:"proxyName,omitempty"` + + // TMC-managed flag indicates if the cluster is managed by tmc. + TmcManaged bool `json:"tmcManaged,omitempty"` + + // The cluster topology. + Topology *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterTopology `json:"topology,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterSpec) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterSpec) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterSpec + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/status.go b/internal/models/tanzukubernetescluster/status.go new file mode 100644 index 000000000..cdb3cf4ba --- /dev/null +++ b/internal/models/tanzukubernetescluster/status.go @@ -0,0 +1,45 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcmodels + +import ( + "github.com/go-openapi/swag" + + statusmodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/status" +) + +// VmwareTanzuManageV1alpha1CommonClusterStatus Status is the common status of the cluster. +// +// swagger:model vmware.tanzu.manage.v1alpha1.common.cluster.Status +type VmwareTanzuManageV1alpha1CommonClusterStatus struct { + + // Conditions of the cluster resource. + Conditions map[string]statusmodel.VmwareTanzuCoreV1alpha1StatusCondition `json:"conditions,omitempty"` + + // Phase of the cluster resource. + Phase *VmwareTanzuManageV1alpha1CommonClusterStatusPhase `json:"phase,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1CommonClusterStatus) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1CommonClusterStatus) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1CommonClusterStatus + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/status_phase.go b/internal/models/tanzukubernetescluster/status_phase.go new file mode 100644 index 000000000..849d7a728 --- /dev/null +++ b/internal/models/tanzukubernetescluster/status_phase.go @@ -0,0 +1,74 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcmodels + +import ( + "encoding/json" +) + +// VmwareTanzuManageV1alpha1CommonClusterStatusPhase Phase of the cluster resource. +// +// - PHASE_UNSPECIFIED: Unspecified phase. +// - CREATING: Resource is being created. +// - READY: Resource is in ready state. +// - DELETING: Resource is being deleted. +// - ERROR: Error in processing. +// - UPGRADING: An upgrade is in progress. +// - UPGRADE_FAILED: An upgrade has failed. +// - UPDATING: The TanzuKubernetescluster of TKGS is in updating phase. +// +// swagger:model vmware.tanzu.manage.v1alpha1.common.cluster.Status.Phase +type VmwareTanzuManageV1alpha1CommonClusterStatusPhase string + +func NewVmwareTanzuManageV1alpha1CommonClusterStatusPhase(value VmwareTanzuManageV1alpha1CommonClusterStatusPhase) *VmwareTanzuManageV1alpha1CommonClusterStatusPhase { + return &value +} + +// Pointer returns a pointer to a freshly-allocated VmwareTanzuManageV1alpha1CommonClusterStatusPhase. +func (m VmwareTanzuManageV1alpha1CommonClusterStatusPhase) Pointer() *VmwareTanzuManageV1alpha1CommonClusterStatusPhase { + return &m +} + +const ( + + // VmwareTanzuManageV1alpha1CommonClusterStatusPhasePHASEUNSPECIFIED captures enum value "PHASE_UNSPECIFIED". + VmwareTanzuManageV1alpha1CommonClusterStatusPhasePHASEUNSPECIFIED VmwareTanzuManageV1alpha1CommonClusterStatusPhase = "PHASE_UNSPECIFIED" + + // VmwareTanzuManageV1alpha1CommonClusterStatusPhaseCREATING captures enum value "CREATING". + VmwareTanzuManageV1alpha1CommonClusterStatusPhaseCREATING VmwareTanzuManageV1alpha1CommonClusterStatusPhase = "CREATING" + + // VmwareTanzuManageV1alpha1CommonClusterStatusPhaseREADY captures enum value "READY". + VmwareTanzuManageV1alpha1CommonClusterStatusPhaseREADY VmwareTanzuManageV1alpha1CommonClusterStatusPhase = "READY" + + // VmwareTanzuManageV1alpha1CommonClusterStatusPhaseDELETING captures enum value "DELETING". + VmwareTanzuManageV1alpha1CommonClusterStatusPhaseDELETING VmwareTanzuManageV1alpha1CommonClusterStatusPhase = "DELETING" + + // VmwareTanzuManageV1alpha1CommonClusterStatusPhaseERROR captures enum value "ERROR". + VmwareTanzuManageV1alpha1CommonClusterStatusPhaseERROR VmwareTanzuManageV1alpha1CommonClusterStatusPhase = "ERROR" + + // VmwareTanzuManageV1alpha1CommonClusterStatusPhaseUPGRADING captures enum value "UPGRADING". + VmwareTanzuManageV1alpha1CommonClusterStatusPhaseUPGRADING VmwareTanzuManageV1alpha1CommonClusterStatusPhase = "UPGRADING" + + // VmwareTanzuManageV1alpha1CommonClusterStatusPhaseUPGRADEFAILED captures enum value "UPGRADE_FAILED". + VmwareTanzuManageV1alpha1CommonClusterStatusPhaseUPGRADEFAILED VmwareTanzuManageV1alpha1CommonClusterStatusPhase = "UPGRADE_FAILED" + + // VmwareTanzuManageV1alpha1CommonClusterStatusPhaseUPDATING captures enum value "UPDATING". + VmwareTanzuManageV1alpha1CommonClusterStatusPhaseUPDATING VmwareTanzuManageV1alpha1CommonClusterStatusPhase = "UPDATING" +) + +// for schema. +var vmwareTanzuManageV1alpha1CommonClusterStatusPhaseEnum []interface{} + +func init() { + var res []VmwareTanzuManageV1alpha1CommonClusterStatusPhase + if err := json.Unmarshal([]byte(`["PHASE_UNSPECIFIED","CREATING","READY","DELETING","ERROR","UPGRADING","UPGRADE_FAILED","UPDATING"]`), &res); err != nil { + panic(err) + } + + for _, v := range res { + vmwareTanzuManageV1alpha1CommonClusterStatusPhaseEnum = append(vmwareTanzuManageV1alpha1CommonClusterStatusPhaseEnum, v) + } +} diff --git a/internal/models/tanzukubernetescluster/tanzu_kubernetes_cluster.go b/internal/models/tanzukubernetescluster/tanzu_kubernetes_cluster.go new file mode 100644 index 000000000..0fd39962a --- /dev/null +++ b/internal/models/tanzukubernetescluster/tanzu_kubernetes_cluster.go @@ -0,0 +1,55 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcmodels + +import ( + "github.com/go-openapi/swag" + + objectmetamodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/objectmeta" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterTanzuKubernetesCluster Tanzu Kubernetes cluster is an object for managed and unmanaged clusters. +// All the workload clusters created on TKG directly or via TMC are termed as TanzuKubernetesCluster. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.TanzuKubernetesCluster +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterTanzuKubernetesCluster struct { + + // Full name for the cluster. + FullName *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterFullName `json:"fullName,omitempty"` + + // Metadata for the cluster object. + Meta *objectmetamodel.VmwareTanzuCoreV1alpha1ObjectMeta `json:"meta,omitempty"` + + // Spec for the cluster. + Spec *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterSpec `json:"spec,omitempty"` + + // Status of the cluster. + Status *VmwareTanzuManageV1alpha1CommonClusterStatus `json:"status,omitempty"` + + // Type meta for resource. + Type *objectmetamodel.VmwareTanzuCoreV1alpha1ObjectType `json:"type,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterTanzuKubernetesCluster) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterTanzuKubernetesCluster) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterTanzuKubernetesCluster + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/models/tanzukubernetescluster/topology.go b/internal/models/tanzukubernetescluster/topology.go new file mode 100644 index 000000000..0fa5d351a --- /dev/null +++ b/internal/models/tanzukubernetescluster/topology.go @@ -0,0 +1,61 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tkcmodels + +import ( + "github.com/go-openapi/swag" + + tkccommon "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/tanzukubernetescluster/common" + tkcnodepool "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/tanzukubernetescluster/nodepool" +) + +// VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterTopology The cluster topology. +// +// swagger:model vmware.tanzu.manage.v1alpha1.managementcluster.provisioner.tanzukubernetescluster.Topology +type VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterTopology struct { + + // The name of the cluster class for the cluster. + ClusterClass string `json:"clusterClass,omitempty"` + + // Control plane specific configuration. + ControlPlane *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterControlPlane `json:"controlPlane,omitempty"` + + // The core addons. + CoreAddons []*VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCoreAddon `json:"coreAddons"` + + // Network specific configuration. + Network *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNetworkSettings `json:"network,omitempty"` + + // Nodepool definition for the cluster. + NodePools []*tkcnodepool.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterNodepoolDefinition `json:"nodePools"` + + // Variables configuration for the cluster. + Variables []*tkccommon.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterCommonClusterClusterVariable `json:"variables"` + + // Kubernetes version of the cluster. + Version string `json:"version,omitempty"` +} + +// MarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterTopology) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation. +func (m *VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterTopology) UnmarshalBinary(b []byte) error { + var res VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterTopology + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + + *m = res + + return nil +} diff --git a/internal/provider/provider.go b/internal/provider/provider.go index f8d26f1c1..5d560645f 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -34,6 +34,7 @@ import ( securitypolicy "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/policy/kind/security" securitypolicyresource "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/policy/kind/security/resource" "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/sourcesecret" + utkgresource "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/tanzukubernetescluster" "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/tanzupackageinstall" packagerepository "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/tanzupackagerepository" "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/workspace" @@ -65,6 +66,7 @@ func Provider() *schema.Provider { packagerepository.ResourceName: packagerepository.ResourcePackageRepository(), tanzupackageinstall.ResourceName: tanzupackageinstall.ResourcePackageInstall(), kubernetessecret.ResourceName: kubernetessecret.ResourceSecret(), + utkgresource.ResourceName: utkgresource.ResourceTanzuKubernetesCluster(), }, DataSourcesMap: map[string]*schema.Resource{ cluster.ResourceName: cluster.DataSourceTMCCluster(), diff --git a/internal/resources/common/meta_flatten_test.go b/internal/resources/common/meta_flatten_test.go index 01def7269..8ee780875 100644 --- a/internal/resources/common/meta_flatten_test.go +++ b/internal/resources/common/meta_flatten_test.go @@ -36,7 +36,7 @@ func TestFlattenMeta(t *testing.T) { }, expected: []interface{}{ map[string]interface{}{ - annotationsKey: map[string]string{"test": "test"}, + AnnotationsKey: map[string]string{"test": "test"}, LabelsKey: map[string]string{"test": "test"}, DescriptionKey: "description of resource", resourceVersionKey: "", @@ -54,7 +54,7 @@ func TestFlattenMeta(t *testing.T) { }, expected: []interface{}{ map[string]interface{}{ - annotationsKey: map[string]string{"test": "test"}, + AnnotationsKey: map[string]string{"test": "test"}, LabelsKey: map[string]string{}, DescriptionKey: "description of resource", resourceVersionKey: "", @@ -72,7 +72,7 @@ func TestFlattenMeta(t *testing.T) { }, expected: []interface{}{ map[string]interface{}{ - annotationsKey: map[string]string{}, + AnnotationsKey: map[string]string{}, LabelsKey: map[string]string{"test": "test"}, DescriptionKey: "", resourceVersionKey: "", diff --git a/internal/resources/common/objectmeta_schema.go b/internal/resources/common/objectmeta_schema.go index 4629b11b8..d958ad484 100644 --- a/internal/resources/common/objectmeta_schema.go +++ b/internal/resources/common/objectmeta_schema.go @@ -20,7 +20,7 @@ const ( MetaKey = "meta" LabelsKey = "labels" DescriptionKey = "description" - annotationsKey = "annotations" + AnnotationsKey = "annotations" uidKey = "uid" resourceVersionKey = "resource_version" CreatorLabelKey = "tmc.cloud.vmware.com/creator" @@ -34,7 +34,7 @@ var Meta = &schema.Schema{ MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - annotationsKey: { + AnnotationsKey: { Type: schema.TypeMap, Description: "Annotations for the resource", Optional: true, @@ -109,7 +109,7 @@ func ConstructMeta(d *schema.ResourceData) (objectMeta *objectmetamodel.VmwareTa objectMetaData := data[0].(map[string]interface{}) - if v, ok := objectMetaData[annotationsKey]; ok { + if v, ok := objectMetaData[AnnotationsKey]; ok { objectMeta.Annotations = GetTypeStringMapData(v.(map[string]interface{})) } @@ -139,7 +139,7 @@ func FlattenMeta(objectMeta *objectmetamodel.VmwareTanzuCoreV1alpha1ObjectMeta) flattenMetaData := make(map[string]interface{}) - flattenMetaData[annotationsKey] = objectMeta.Annotations + flattenMetaData[AnnotationsKey] = objectMeta.Annotations flattenMetaData[LabelsKey] = objectMeta.Labels flattenMetaData[DescriptionKey] = objectMeta.Description flattenMetaData[uidKey] = objectMeta.UID @@ -172,7 +172,7 @@ func GetTypeIntMapData(data map[string]interface{}) map[string]int { // MetaConverterMap mapping for converter. var MetaConverterMap = &converter.BlockToStruct{ - annotationsKey: &converter.Map{ + AnnotationsKey: &converter.Map{ "*": "meta.annotations.*", }, LabelsKey: &converter.Map{ diff --git a/internal/resources/tanzukubernetescluster/converter_mapping.go b/internal/resources/tanzukubernetescluster/converter_mapping.go new file mode 100644 index 000000000..7bca373ec --- /dev/null +++ b/internal/resources/tanzukubernetescluster/converter_mapping.go @@ -0,0 +1,88 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tanzukubernetescluster + +import ( + tfModelConverterHelper "github.com/vmware/terraform-provider-tanzu-mission-control/internal/helper/converter" + tanzukubernetesclustermodels "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/tanzukubernetescluster" + "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common" +) + +var tfModelResourceMap = &tfModelConverterHelper.BlockToStruct{ + NameKey: "fullName.name", + ManagementClusterNameKey: "fullName.managementClusterName", + ProvisionerNameKey: "fullName.provisionerName", + common.MetaKey: common.MetaConverterMap, + SpecKey: &tfModelConverterHelper.BlockToStruct{ + ClusterGroupNameKey: "spec.clusterGroupName", + ImageRegistryKey: "spec.imageRegistry", + ProxyNameKey: "spec.proxyName", + TMCManagedKey: "spec.tmcManaged", + TopologyKey: &tfModelConverterHelper.BlockToStruct{ + ClusterClassKey: "spec.topology.clusterClass", + VersionKey: "spec.topology.version", + NodePoolKey: &tfModelConverterHelper.BlockSliceToStructSlice{ + { + NameKey: "spec.topology.nodePools[].info.name", + DescriptionKey: "spec.topology.nodePools[].info.description", + SpecKey: &tfModelConverterHelper.BlockToStruct{ + WorkerClassKey: "spec.topology.nodePools[].spec.class", + FailureDomainKey: "spec.topology.nodePools[].spec.failureDomain", + common.MetaKey: &tfModelConverterHelper.BlockToStruct{ + common.LabelsKey: "spec.topology.nodePools[].spec.metadata.labels", + common.AnnotationsKey: "spec.topology.nodePools[].spec.metadata.annotations", + }, + ReplicasKey: "spec.topology.nodePools[].spec.replicas", + OSImageKey: &tfModelConverterHelper.BlockToStruct{ + NameKey: "spec.topology.nodePools[].spec.osImage.name", + OSArchKey: "spec.topology.nodePools[].spec.osImage.arch", + VersionKey: "spec.topology.nodePools[].spec.osImage.version", + }, + OverridesKey: &tfModelConverterHelper.EvaluatedField{ + Field: "spec.topology.nodePools[].spec.overrides[]", + EvalFunc: tfModelConverterHelper.EvaluationFunc(evaluateClusterVariables), + }, + }, + }, + }, + CoreAddonKey: &tfModelConverterHelper.BlockSliceToStructSlice{ + { + TypeKey: "spec.topology.coreAddons[].type", + ProviderKey: "spec.topology.coreAddons[].provider", + }, + }, + NetworkKey: &tfModelConverterHelper.BlockToStruct{ + PodCIDRBlocksKey: "spec.topology.network.pods.cidrBlocks", + ServiceCIDRBlocksKey: "spec.topology.network.services.cidrBlocks", + ServiceDomainKey: "spec.topology.network.serviceDomain", + }, + ControlPlaneKey: &tfModelConverterHelper.BlockToStruct{ + ReplicasKey: "spec.topology.controlPlane.replicas", + OSImageKey: &tfModelConverterHelper.BlockToStruct{ + NameKey: "spec.topology.controlPlane.osImage.name", + OSArchKey: "spec.topology.controlPlane.osImage.arch", + VersionKey: "spec.topology.controlPlane.osImage.version", + }, + common.MetaKey: &tfModelConverterHelper.BlockToStruct{ + common.LabelsKey: "spec.topology.controlPlane.metadata.Labels", + common.AnnotationsKey: "spec.topology.controlPlane.metadata.annotations", + }, + }, + ClusterVariablesKey: &tfModelConverterHelper.EvaluatedField{ + Field: "spec.topology.variables[]", + EvalFunc: tfModelConverterHelper.EvaluationFunc(evaluateClusterVariables), + }, + }, + }, +} + +var tfModelResourceConverter = tfModelConverterHelper.TFSchemaModelConverter[*tanzukubernetesclustermodels.VmwareTanzuManageV1alpha1ManagementclusterProvisionerTanzukubernetesclusterTanzuKubernetesCluster]{ + TFModelMap: tfModelResourceMap, +} + +func evaluateClusterVariables(mode tfModelConverterHelper.EvaluationMode, value interface{}) interface{} { + return nil +} diff --git a/internal/resources/tanzukubernetescluster/resource_tanzu_kuberenetes_cluster.go b/internal/resources/tanzukubernetescluster/resource_tanzu_kuberenetes_cluster.go new file mode 100644 index 000000000..04eb547d6 --- /dev/null +++ b/internal/resources/tanzukubernetescluster/resource_tanzu_kuberenetes_cluster.go @@ -0,0 +1,16 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tanzukubernetescluster + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func ResourceTanzuKubernetesCluster() *schema.Resource { + return &schema.Resource{ + Schema: tanzuKubernetesClusterSchema, + } +} diff --git a/internal/resources/tanzukubernetescluster/schema.go b/internal/resources/tanzukubernetescluster/schema.go new file mode 100644 index 000000000..df83ab345 --- /dev/null +++ b/internal/resources/tanzukubernetescluster/schema.go @@ -0,0 +1,296 @@ +/* +Copyright © 2023 VMware, Inc. All Rights Reserved. +SPDX-License-Identifier: MPL-2.0 +*/ + +package tanzukubernetescluster + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common" +) + +const ( + ResourceName = "tanzu-mission-control_tanzu_kubernetes_cluster" + + // Common Keys. + NameKey = "name" + SpecKey = "spec" + DescriptionKey = "description" + VersionKey = "version" + ReplicasKey = "replicas" + OSImageKey = "os_image" + OSArchKey = "arch" + + // Root Keys. + ManagementClusterNameKey = "management_cluster_name" + ProvisionerNameKey = "provisioner_name" + + // Spec Directive Keys. + ClusterGroupNameKey = "cluster_group_name" + TMCManagedKey = "tmc_managed" + ProxyNameKey = "proxy_name" + ImageRegistryKey = "image_registry" + TopologyKey = "topology" + + // Topology Directive Keys. + ClusterClassKey = "cluster_class" + ControlPlaneKey = "control_plane" + NodePoolKey = "nodepool" + ClusterVariablesKey = "cluster_variables" + NetworkKey = "network" + CoreAddonKey = "core_addon" + + // Node Pool Directive Keys. + WorkerClassKey = "worker_class" + FailureDomainKey = "failure_domain" + OverridesKey = "overrides" + + // Network Directive Keys. + PodCIDRBlocksKey = "pod_cidr_blocks" + ServiceCIDRBlocksKey = "service_cidr_blocks" + ServiceDomainKey = "service_domain" + + // Core Addon Directive Keys. + TypeKey = "type" + ProviderKey = "provider" +) + +var tanzuKubernetesClusterSchema = map[string]*schema.Schema{ + NameKey: clusterNameSchema, + ManagementClusterNameKey: managementClusterNameSchema, + ProvisionerNameKey: provisionerNameSchema, + SpecKey: specSchema, + common.MetaKey: common.Meta, +} + +var clusterNameSchema = &schema.Schema{ + Type: schema.TypeString, + Description: "Cluster name", + Required: true, + ForceNew: true, +} + +var managementClusterNameSchema = &schema.Schema{ + Type: schema.TypeString, + Description: "Management cluster name", + Required: true, + ForceNew: true, +} + +var provisionerNameSchema = &schema.Schema{ + Type: schema.TypeString, + Description: "Cluster provisioner name", + Required: true, + ForceNew: true, +} + +var specSchema = &schema.Schema{ + Type: schema.TypeList, + Description: "Spec of tanzu kubernetes cluster (Unified TKG)", + Required: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + ClusterGroupNameKey: { + Type: schema.TypeString, + Description: "Name of the cluster group to which this cluster belongs.", + Default: "default", + Optional: true, + }, + TMCManagedKey: { + Type: schema.TypeBool, + Description: "TMC-managed flag indicates if the cluster is managed by tmc.\n(Default: False)", + Default: false, + Optional: true, + }, + ProxyNameKey: { + Type: schema.TypeString, + Description: "Name of the proxy configuration to use.", + Optional: true, + }, + ImageRegistryKey: { + Type: schema.TypeString, + Description: "Name of the image registry configuration to use.", + Optional: true, + }, + TopologyKey: TopologySchema, + }, + }, +} + +var TopologySchema = &schema.Schema{ + Type: schema.TypeList, + Description: "The cluster topology.", + Required: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + VersionKey: { + Type: schema.TypeString, + Description: "Kubernetes version of the cluster.", + Required: true, + }, + ClusterClassKey: { + Type: schema.TypeString, + Description: "The name of the cluster class for the cluster.", + Required: true, + }, + ClusterVariablesKey: { + Type: schema.TypeString, + Description: "Variables configuration for the cluster.", + Required: true, + }, + CoreAddonKey: { + Type: schema.TypeList, + Description: "(Repeatable Block) The core addons.", + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + TypeKey: { + Type: schema.TypeString, + Description: "Type of core add on", + Required: true, + }, + ProviderKey: { + Type: schema.TypeString, + Description: "Provider of core add on", + Required: true, + }, + }, + }, + }, + NetworkKey: NetworkSchema, + ControlPlaneKey: ControlPlaneSchema, + NodePoolKey: NodePoolSchema, + }, + }, +} + +var NetworkSchema = &schema.Schema{ + Type: schema.TypeList, + Description: "Network specific configuration.", + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + PodCIDRBlocksKey: { + Type: schema.TypeList, + Description: "Pod CIDR for Kubernetes pods defaults to 192.168.0.0/16.", + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + ServiceCIDRBlocksKey: { + Type: schema.TypeList, + Description: "Service CIDR for kubernetes services defaults to 10.96.0.0/12.", + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + ServiceDomainKey: { + Type: schema.TypeString, + Description: "Domain name for services.", + Optional: true, + }, + }, + }, +} + +var ControlPlaneSchema = &schema.Schema{ + Type: schema.TypeList, + Description: "Control plane specific configuration.", + MaxItems: 1, + Required: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + ReplicasKey: ReplicasSchema, + OSImageKey: OSImageSchema, + common.MetaKey: common.Meta, + }, + }, +} + +var NodePoolSchema = &schema.Schema{ + Type: schema.TypeList, + Description: "(Repeatable Block) Node pool definition for the cluster.", + Required: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + NameKey: { + Type: schema.TypeString, + Description: "Name of the node pool.", + Required: true, + }, + DescriptionKey: { + Type: schema.TypeString, + Description: "Description for the node pool.", + Optional: true, + }, + SpecKey: NodePoolSpecSchema, + }, + }, +} + +var NodePoolSpecSchema = &schema.Schema{ + Type: schema.TypeList, + Description: "Spec for the node pool.", + MaxItems: 1, + Required: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + WorkerClassKey: { + Type: schema.TypeString, + Description: "The name of the machine deployment class used to create the node pool.", + Required: true, + }, + FailureDomainKey: { + Type: schema.TypeString, + Description: "The failure domain the machines will be created in.", + Optional: true, + }, + OverridesKey: { + Type: schema.TypeString, + Description: "Overrides can be used to override cluster level variables.", + Optional: true, + }, + ReplicasKey: ReplicasSchema, + OSImageKey: OSImageSchema, + common.MetaKey: common.Meta, + }, + }, +} + +var ReplicasSchema = &schema.Schema{ + Type: schema.TypeInt, + Description: "Number of replicas", + Required: true, +} + +var OSImageSchema = &schema.Schema{ + Type: schema.TypeList, + Description: "OS image block", + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + NameKey: { + Type: schema.TypeString, + Description: "The name of the OS image.", + Required: true, + }, + VersionKey: { + Type: schema.TypeString, + Description: "The version of the OS image.", + Required: true, + }, + OSArchKey: { + Type: schema.TypeString, + Description: "The architecture of the OS image.", + Required: true, + }, + }, + }, +}