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 all 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 @@ -5,16 +5,15 @@
"crypto/tls"
"net/http"

openapiclient "github.com/go-openapi/runtime/client"

Check failure on line 8 in client/client.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

missing go.sum entry for module providing package github.com/go-openapi/runtime/client (imported by github.com/spectrocloud/palette-sdk-go/client); to add:
"github.com/go-openapi/strfmt"

Check failure on line 9 in client/client.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

missing go.sum entry for module providing package github.com/go-openapi/strfmt (imported by github.com/spectrocloud/palette-sdk-go/client); to add:

"github.com/spectrocloud/palette-api-go/apiutil/transport"

Check failure on line 11 in client/client.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

github.com/spectrocloud/[email protected]: replacement directory ../palette-api-go does not exist
clientV1 "github.com/spectrocloud/palette-api-go/client/v1"
"github.com/spectrocloud/palette-api-go/models"
)

type V1Client struct {

Client clientV1.ClientService

ctx context.Context
Expand Down Expand Up @@ -73,6 +72,12 @@
}
}

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 @@
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 @@
}
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,
}})
}
10 changes: 10 additions & 0 deletions client/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,13 @@ func (h *V1Client) DownloadLogs(uid string, logFetcherUid string) (io.Writer, er
}
return logfile, nil
}

func (h *V1Client) UpdatePauseAgentUpgradeSettingCluster(upgradeSetting *models.V1ClusterUpgradeSettingsEntity, clusterUID string) error {
params := clientV1.NewV1SpectroClustersUIDUpgradeSettingsParamsWithContext(h.ctx)
params = params.WithUID(clusterUID).WithBody(upgradeSetting)
_, err := h.Client.V1SpectroClustersUIDUpgradeSettings(params)
if err != nil {
return err
}
return nil
}
71 changes: 0 additions & 71 deletions client/cluster_edge.go

This file was deleted.

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"

Check failure on line 5 in client/cluster_profile_import.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

missing go.sum entry for module providing package github.com/go-openapi/runtime (imported by github.com/spectrocloud/palette-sdk-go/client); to add:

"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 @@
}
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
}
26 changes: 0 additions & 26 deletions client/node_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,6 @@ 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) GetNodeMaintenanceStatusEdgeNative(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) {
params := clientV1.NewV1CloudConfigsEdgeNativePoolMachinesUIDGetParamsWithContext(h.ctx).
WithConfigUID(configUid).
Expand All @@ -101,19 +88,6 @@ 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) GetNodeMaintenanceStatusEdgeVsphere(configUid, machineName, nodeId string) (*models.V1MachineMaintenanceStatus, error) {
params := clientV1.NewV1CloudConfigsVspherePoolMachinesUIDGetParamsWithContext(h.ctx).
WithConfigUID(configUid).
Expand Down
38 changes: 20 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,42 @@ module github.com/spectrocloud/palette-sdk-go
go 1.22

require (
github.com/go-openapi/runtime v0.26.0
github.com/go-openapi/strfmt v0.21.7
github.com/go-openapi/runtime v0.28.0
github.com/go-openapi/strfmt v0.23.0
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/stretchr/testify v1.8.4
github.com/spectrocloud/palette-api-go v0.2.5
github.com/stretchr/testify v1.9.0
)

require (
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-errors/errors v1.5.1 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/errors v0.20.4 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/loads v0.21.2 // indirect
github.com/go-openapi/spec v0.20.9 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-openapi/validate v0.22.1 // indirect
github.com/go-openapi/analysis v0.23.0 // indirect
github.com/go-openapi/errors v0.22.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/loads v0.22.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-openapi/validate v0.24.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
go.mongodb.org/mongo-driver v1.12.1 // indirect
go.opentelemetry.io/otel v1.18.0 // indirect
go.opentelemetry.io/otel/metric v1.18.0 // indirect
go.opentelemetry.io/otel/trace v1.18.0 // indirect
golang.org/x/sys v0.12.0 // indirect
go.mongodb.org/mongo-driver v1.16.0 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
golang.org/x/sys v0.22.0 // indirect
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
Loading
Loading