Skip to content

Commit

Permalink
Rebase UTKG - Squash - Client + Models + Schema + Converter Mapping
Browse files Browse the repository at this point in the history
Signed-off-by: GilTS <[email protected]>
  • Loading branch information
GilTeraSky committed Oct 17, 2023
1 parent adc428d commit 3a9f41c
Show file tree
Hide file tree
Showing 41 changed files with 2,134 additions and 10 deletions.
58 changes: 58 additions & 0 deletions internal/client/clusterclass/clusterclass_resource.go
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 6 additions & 0 deletions internal/client/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -154,4 +158,6 @@ type TanzuMissionControl struct {
ClusterTanzuPackageService tanzupackageclusterclient.ClientService
TanzupackageResourceService packageclusterclient.ClientService
PackageInstallResourceService pkginstallclusterclient.ClientService
ClusterClassResourceService clusterclassclient.ClientService
TanzuKubernetesClusterResourceService tanzukubernetesclusterclient.ClientService
}
Original file line number Diff line number Diff line change
@@ -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
}
14 changes: 12 additions & 2 deletions internal/helper/converter/map_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
50 changes: 50 additions & 0 deletions internal/models/clusterclass/clusterclass.go
Original file line number Diff line number Diff line change
@@ -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"

Check failure on line 9 in internal/models/clusterclass/clusterclass.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed with -local github.com/vmware/terraform-provider-tanzu-mission-control (goimports)

Check failure on line 9 in internal/models/clusterclass/clusterclass.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed with -local github.com/vmware/terraform-provider-tanzu-mission-control (goimports)
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)

Check failure on line 39 in internal/models/clusterclass/clusterclass.go

View workflow job for this annotation

GitHub Actions / lint

return statements should not be cuddled if block has more than two lines (wsl)

Check failure on line 39 in internal/models/clusterclass/clusterclass.go

View workflow job for this annotation

GitHub Actions / lint

return statements should not be cuddled if block has more than two lines (wsl)
}

// 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

Check failure on line 48 in internal/models/clusterclass/clusterclass.go

View workflow job for this annotation

GitHub Actions / lint

assignments should only be cuddled with other assignments (wsl)

Check failure on line 48 in internal/models/clusterclass/clusterclass.go

View workflow job for this annotation

GitHub Actions / lint

assignments should only be cuddled with other assignments (wsl)
return nil

Check failure on line 49 in internal/models/clusterclass/clusterclass.go

View workflow job for this annotation

GitHub Actions / lint

return statements should not be cuddled if block has more than two lines (wsl)

Check failure on line 49 in internal/models/clusterclass/clusterclass.go

View workflow job for this annotation

GitHub Actions / lint

return statements should not be cuddled if block has more than two lines (wsl)
}
47 changes: 47 additions & 0 deletions internal/models/clusterclass/fullname.go
Original file line number Diff line number Diff line change
@@ -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)

Check failure on line 36 in internal/models/clusterclass/fullname.go

View workflow job for this annotation

GitHub Actions / lint

return statements should not be cuddled if block has more than two lines (wsl)

Check failure on line 36 in internal/models/clusterclass/fullname.go

View workflow job for this annotation

GitHub Actions / lint

return statements should not be cuddled if block has more than two lines (wsl)
}

// 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

Check failure on line 45 in internal/models/clusterclass/fullname.go

View workflow job for this annotation

GitHub Actions / lint

assignments should only be cuddled with other assignments (wsl)

Check failure on line 45 in internal/models/clusterclass/fullname.go

View workflow job for this annotation

GitHub Actions / lint

assignments should only be cuddled with other assignments (wsl)
return nil
}
40 changes: 40 additions & 0 deletions internal/models/clusterclass/request.go
Original file line number Diff line number Diff line change
@@ -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

Check failure on line 38 in internal/models/clusterclass/request.go

View workflow job for this annotation

GitHub Actions / lint

assignments should only be cuddled with other assignments (wsl)

Check failure on line 38 in internal/models/clusterclass/request.go

View workflow job for this annotation

GitHub Actions / lint

assignments should only be cuddled with other assignments (wsl)
return nil
}
Loading

0 comments on commit 3a9f41c

Please sign in to comment.