-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #345 from replicatedhq/joshd/sc-82847/ability-to-e…
…xtend-cluster-ttl-after-creation Adding command to update ttl
- Loading branch information
Showing
5 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func (r *runners) InitClusterUpdateCommand(parent *cobra.Command) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "update", | ||
Short: "Update cluster settings", | ||
Long: `cluster update can be used to update cluster settings`, | ||
} | ||
parent.AddCommand(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"github.com/replicatedhq/replicated/cli/print" | ||
"github.com/replicatedhq/replicated/pkg/kotsclient" | ||
"github.com/replicatedhq/replicated/pkg/platformclient" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func (r *runners) InitClusterUpdateTTL(parent *cobra.Command) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "ttl", | ||
Short: "Update TTL for a test clusters", | ||
Long: `Update TTL for a test clusters`, | ||
Args: cobra.ExactArgs(1), | ||
RunE: r.updateClusterTTL, | ||
SilenceUsage: true, | ||
} | ||
parent.AddCommand(cmd) | ||
|
||
cmd.Flags().StringVar(&r.args.updateClusterTTL, "ttl", "", "Cluster TTL (duration, max 48h)") | ||
|
||
cmd.Flags().StringVar(&r.outputFormat, "output", "table", "The output format to use. One of: json|table (default: table)") | ||
|
||
_ = cmd.MarkFlagRequired("ttl") | ||
|
||
return cmd | ||
} | ||
|
||
func (r *runners) updateClusterTTL(cmd *cobra.Command, args []string) error { | ||
if len(args) < 1 { | ||
return errors.New("cluster id is required") | ||
} | ||
clusterID := args[0] | ||
|
||
opts := kotsclient.UpdateClusterTTLOpts{ | ||
TTL: r.args.updateClusterTTL, | ||
} | ||
cl, err := r.kotsAPI.UpdateClusterTTL(clusterID, opts) | ||
if errors.Cause(err) == platformclient.ErrForbidden { | ||
return ErrCompatibilityMatrixTermsNotAccepted | ||
} else if err != nil { | ||
return errors.Wrap(err, "update cluster ttl") | ||
} | ||
|
||
return print.Cluster(r.outputFormat, r.w, cl) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package kotsclient | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/replicatedhq/replicated/pkg/types" | ||
) | ||
|
||
type UpdateClusterTTLRequest struct { | ||
TTL string `json:"ttl"` | ||
} | ||
|
||
type UpdateClusterTTLResponse struct { | ||
Cluster *types.Cluster `json:"cluster"` | ||
Errors []string `json:"errors"` | ||
} | ||
|
||
type UpdateClusterTTLOpts struct { | ||
TTL string | ||
} | ||
|
||
func (c *VendorV3Client) UpdateClusterTTL(clusterID string, opts UpdateClusterTTLOpts) (*types.Cluster, error) { | ||
req := UpdateClusterTTLRequest{ | ||
TTL: opts.TTL, | ||
} | ||
|
||
return c.doUpdateClusterTTLRequest(clusterID, req) | ||
} | ||
|
||
func (c *VendorV3Client) doUpdateClusterTTLRequest(clusterID string, req UpdateClusterTTLRequest) (*types.Cluster, error) { | ||
resp := UpdateClusterTTLResponse{} | ||
endpoint := fmt.Sprintf("/v3/cluster/%s/ttl", clusterID) | ||
err := c.DoJSON("PUT", endpoint, http.StatusOK, req, &resp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return resp.Cluster, nil | ||
} |