Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLT-1259: SDK Cut over with 4.3 changes #114

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
)

type V1Client struct {

Client clientV1.ClientService

ctx context.Context
Expand Down Expand Up @@ -73,6 +72,12 @@ func WithHubbleURI(hubbleUri string) func(*V1Client) {
}
}

func SetProjectUID(projectUid string) func(*V1Client) {
return func(v *V1Client) {
v.projectUid = projectUid
}
}

func WithInsecureSkipVerify(insecureSkipVerify bool) func(*V1Client) {
return func(v *V1Client) {
v.insecureSkipVerify = insecureSkipVerify
Expand Down Expand Up @@ -202,6 +207,11 @@ func (h *V1Client) baseTransport() *transport.Runtime {
return httpTransport
}

func (h *V1Client) SetProjectContextForResource() *V1Client {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be accomplished by calling WithScopeProject. Please remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required because in Terraform, we have the provision to set resource-level context.

During provider initialization, we use project scope or tenant scope based on the user settings during initialization. Later on, the user can also set the context at the resource level (if user have right access).

For example, a user can initialize the client with project scope and then switch to create a resource at the tenant level as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that, but there's already a way that you can handle the requirement without introducing a new method on the V1Client.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ping me and we can discuss.

h.ctx = ContextWithProject(h.ctx, h.projectUid)
return h
}

func (h *V1Client) httpClient() *http.Client {
return &http.Client{
Transport: &http.Transport{
Expand Down Expand Up @@ -234,3 +244,10 @@ func (h *V1Client) ValidateTenantAdmin() error {
}
return nil
}

func ContextWithProject(c context.Context, projectUid string) context.Context {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above comment. This function should not be required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required because in Terraform, we have the provision to set resource-level context.

During provider initialization, we use project scope or tenant scope based on the user settings during initialization. Later on, the user can also set the context at the resource level (if user have right access).

For example, a user can initialize the client with project scope and then switch to create a resource at the tenant level as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. Let's discuss.

return context.WithValue(c, transport.CUSTOM_HEADERS, transport.Values{
HeaderMap: map[string]string{
"ProjectUid": projectUid,
}})
}
11 changes: 11 additions & 0 deletions client/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,14 @@ func (h *V1Client) DownloadLogs(uid string, logFetcherUid string) (io.Writer, er
}
return logfile, nil
}

func (h *V1Client) UpdatePauseAgentUpgradeSettingCluster(upgradeSetting *models.V1ClusterUpgradeSettingsEntity, clusterUID string, context string) error {
SivaanandM marked this conversation as resolved.
Show resolved Hide resolved

//params := clientV1.NewV1SpectroClustersUIDUpgradeSettingsParamsWithContext(h.ctx)
//params = params.WithUID(clusterUID).WithBody(upgradeSetting)
//_, err := h.GetClusterClient().V1SpectroClustersUIDUpgradeSettings(params)
//if err != nil {
// return err
//}
return nil
}
SivaanandM marked this conversation as resolved.
Show resolved Hide resolved
File renamed without changes.
18 changes: 17 additions & 1 deletion client/cluster_profile_import.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package client

import (
"errors"
"github.com/go-openapi/runtime"

"github.com/spectrocloud/palette-api-go/apiutil/transport"
clientV1 "github.com/spectrocloud/palette-api-go/client/v1"
"github.com/spectrocloud/palette-api-go/models"
"github.com/spectrocloud/palette-sdk-go/client/apiutil"
)

Expand All @@ -17,3 +19,17 @@ func (h *V1Client) CreateClusterProfileImport(importFile runtime.NamedReadCloser
}
return *resp.Payload.UID, nil
}

func (h *V1Client) ClusterProfileExport(uid string) (*models.V1ClusterProfile, error) {
// no need to switch request context here as /v1/clusterprofiles/{uid} works for profile in any scope.
params := clientV1.NewV1ClusterProfilesGetParamsWithContext(h.ctx).WithUID(uid)
success, err := h.Client.V1ClusterProfilesGet(params)
var e *transport.TransportError
if errors.As(err, &e) && e.HttpCode == 404 {
return nil, nil
} else if err != nil {
return nil, err
}

return success.Payload, nil
}
48 changes: 24 additions & 24 deletions client/node_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ func (h *V1Client) GetNodeMaintenanceStatusAzure(configUid, machineName, nodeId
return resp.Payload.Status.MaintenanceStatus, nil
}

func (h *V1Client) GetNodeMaintenanceStatusCoxEdge(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) {
params := clientV1.NewV1CloudConfigsCoxEdgePoolMachinesUIDGetParamsWithContext(h.ctx).
WithConfigUID(configUid).
WithMachinePoolName(machineName).
WithMachineUID(nodeId)

resp, err := h.Client.V1CloudConfigsCoxEdgePoolMachinesUIDGet(params)
if err != nil {
return nil, err
}
return resp.Payload.Status.MaintenanceStatus, nil
}
//func (h *V1Client) GetNodeMaintenanceStatusCoxEdge(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) {
TylerGillson marked this conversation as resolved.
Show resolved Hide resolved
// params := clientV1.NewV1CloudConfigsCoxEdgePoolMachinesUIDGetParamsWithContext(h.ctx).
// WithConfigUID(configUid).
// WithMachinePoolName(machineName).
// WithMachineUID(nodeId)
//
// resp, err := h.Client.V1CloudConfigsCoxEdgePoolMachinesUIDGet(params)
// if err != nil {
// return nil, err
// }
// return resp.Payload.Status.MaintenanceStatus, nil
//}

func (h *V1Client) GetNodeMaintenanceStatusEdgeNative(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) {
params := clientV1.NewV1CloudConfigsEdgeNativePoolMachinesUIDGetParamsWithContext(h.ctx).
Expand All @@ -101,18 +101,18 @@ func (h *V1Client) GetNodeMaintenanceStatusEdgeNative(configUid, machineName, no
return resp.Payload.Status.MaintenanceStatus, nil
}

func (h *V1Client) GetNodeMaintenanceStatusEdge(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) {
params := clientV1.NewV1CloudConfigsEdgePoolMachinesUIDGetParamsWithContext(h.ctx).
WithConfigUID(configUid).
WithMachinePoolName(machineName).
WithMachineUID(nodeId)

resp, err := h.Client.V1CloudConfigsEdgePoolMachinesUIDGet(params)
if err != nil {
return nil, err
}
return resp.Payload.Status.MaintenanceStatus, nil
}
//func (h *V1Client) GetNodeMaintenanceStatusEdge(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) {
TylerGillson marked this conversation as resolved.
Show resolved Hide resolved
// params := clientV1.NewV1CloudConfigsEdgePoolMachinesUIDGetParamsWithContext(h.ctx).
// WithConfigUID(configUid).
// WithMachinePoolName(machineName).
// WithMachineUID(nodeId)
//
// resp, err := h.Client.V1CloudConfigsEdgePoolMachinesUIDGet(params)
// if err != nil {
// return nil, err
// }
// return resp.Payload.Status.MaintenanceStatus, nil
//}

func (h *V1Client) GetNodeMaintenanceStatusEdgeVsphere(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) {
params := clientV1.NewV1CloudConfigsVspherePoolMachinesUIDGetParamsWithContext(h.ctx).
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/go-openapi/strfmt v0.21.7
github.com/pkg/errors v0.9.1
github.com/spectrocloud/gomi v1.14.0
github.com/spectrocloud/palette-api-go v0.2.3
github.com/spectrocloud/palette-api-go v0.2.5
github.com/stretchr/testify v1.8.4
)

Expand Down Expand Up @@ -40,3 +40,5 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

//replace github.com/spectrocloud/palette-api-go => ../palette-api-go
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4k
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spectrocloud/gomi v1.14.0 h1:XwOqPssfX1D1tRr1EzUgRULrdncubZG1O/zp/7DuSyU=
github.com/spectrocloud/gomi v1.14.0/go.mod h1:rPAwipFWzjYkTfx44KmQazP1NR2cnHe7HSFZkc63mf4=
github.com/spectrocloud/palette-api-go v0.2.3 h1:U2SikdUA9iGo1N/OkpnO61T2Dxlz70yfur1YFiLDZb8=
github.com/spectrocloud/palette-api-go v0.2.3/go.mod h1:9ebu529ThhudXje/65A2kjdngBN0sf1ei/DDrXgYPQM=
github.com/spectrocloud/palette-api-go v0.2.5 h1:x4oJZGtqQ/ijm4j4M0lRZ28TpznHDkOEQQQ6L56UYG8=
github.com/spectrocloud/palette-api-go v0.2.5/go.mod h1:9ebu529ThhudXje/65A2kjdngBN0sf1ei/DDrXgYPQM=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/cast v1.2.0/go.mod h1:r2rcYCSwa1IExKTDiTfzaxqT2FNHs8hODu4LnUfgKEg=
Expand Down
Loading