-
Notifications
You must be signed in to change notification settings - Fork 26
Add support for demote/un-demote of chan releases #496
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
17cc82c
Add support for demote/undemote of chan releases
pandemicsyn 1bd509c
Merge branch 'main' into feat/demote-channel-release
pandemicsyn d727439
clean up unused funcs and vars
pandemicsyn 6111370
only display chan sequence when actually set
pandemicsyn db9182c
fix subcmd's example usage
pandemicsyn 4352e21
fix example usage for enable/disable semantic versioning cmds
pandemicsyn de5762d
Revert "fix example usage for enable/disable semantic versioning cmds"
pandemicsyn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,85 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/replicatedhq/replicated/client" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func (r *runners) InitChannelReleaseDemote(parent *cobra.Command) { | ||
cmd := &cobra.Command{ | ||
Use: "demote CHANNEL_ID_OR_NAME", | ||
Short: "Demote a release from a channel", | ||
Long: "Demote a channel release from a channel using a channel sequence or release sequence.", | ||
Example: ` # Demote a release from a channel by channel sequence | ||
replicated channel release demote Beta --channel-sequence 15 | ||
|
||
# Demote a release from a channel by release sequence | ||
replicated channel release demote Beta --release-sequence 12`, | ||
Args: cobra.ExactArgs(1), | ||
} | ||
|
||
cmd.Flags().Int64Var(&r.args.demoteChannelSequence, "channel-sequence", 0, "The channel sequence to demote") | ||
cmd.Flags().Int64Var(&r.args.demoteReleaseSequence, "release-sequence", 0, "The release sequence to demote") | ||
|
||
parent.AddCommand(cmd) | ||
cmd.RunE = r.channelReleaseDemote | ||
} | ||
|
||
func (r *runners) channelReleaseDemote(cmd *cobra.Command, args []string) error { | ||
if !r.hasApp() { | ||
return errors.New("no app specified") | ||
} | ||
|
||
if r.args.demoteChannelSequence == 0 && r.args.demoteReleaseSequence == 0 { | ||
return errors.New("one of --channel-sequence or --release-sequence is required") | ||
} | ||
|
||
if r.args.demoteChannelSequence != 0 && r.args.demoteReleaseSequence != 0 { | ||
fmt.Fprintf(r.w, "Warning: Both --channel-sequence and --release-sequence provided. Using --channel-sequence %d\n", r.args.demoteChannelSequence) | ||
} | ||
|
||
chanID := args[0] | ||
|
||
opts := client.GetOrCreateChannelOptions{ | ||
AppID: r.appID, | ||
AppType: r.appType, | ||
NameOrID: chanID, | ||
CreateIfAbsent: false, | ||
} | ||
foundChannel, err := r.api.GetOrCreateChannelByName(opts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
channelSequence := r.args.demoteChannelSequence | ||
if r.args.demoteReleaseSequence != 0 { | ||
kotsChannel, err := r.api.KotsClient.GetKotsChannel(r.appID, foundChannel.ID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, channelRelease := range kotsChannel.Releases { | ||
if int64(channelRelease.Sequence) == r.args.demoteReleaseSequence { | ||
channelSequence = int64(channelRelease.ChannelSequence) | ||
break | ||
} | ||
} | ||
|
||
if channelSequence == 0 { | ||
return fmt.Errorf("release sequence %d not found in channel %s", r.args.demoteReleaseSequence, foundChannel.ID) | ||
} | ||
} | ||
|
||
demotedRelease, err := r.api.ChannelReleaseDemote(r.appID, r.appType, foundChannel.ID, channelSequence) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Fprintf(r.w, "Channel sequence %d (version %s, release %d) demoted in channel %s\n", channelSequence, demotedRelease.Semver, demotedRelease.Sequence, chanID) | ||
r.w.Flush() | ||
|
||
return nil | ||
} |
This file contains hidden or 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,85 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/replicatedhq/replicated/client" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func (r *runners) InitChannelReleaseUnDemote(parent *cobra.Command) { | ||
cmd := &cobra.Command{ | ||
Use: "un-demote CHANNEL_ID_OR_NAME", | ||
Short: "Un-demote a release from a channel", | ||
Long: "Un-demote a channel release from a channel using a channel sequence or release sequence.", | ||
Example: ` # Un-demote a release from a channel by channel sequence | ||
replicated channel release un-demote Beta --channel-sequence 15 | ||
|
||
# Un-demote a release from a channel by release sequence | ||
replicated channel release un-demote Beta --release-sequence 12`, | ||
Args: cobra.ExactArgs(1), | ||
} | ||
|
||
cmd.Flags().Int64Var(&r.args.unDemoteChannelSequence, "channel-sequence", 0, "The channel sequence to un-demote") | ||
cmd.Flags().Int64Var(&r.args.unDemoteReleaseSequence, "release-sequence", 0, "The release sequence to un-demote") | ||
|
||
parent.AddCommand(cmd) | ||
cmd.RunE = r.channelReleaseUnDemote | ||
} | ||
|
||
func (r *runners) channelReleaseUnDemote(cmd *cobra.Command, args []string) error { | ||
if !r.hasApp() { | ||
return errors.New("no app specified") | ||
} | ||
|
||
if r.args.unDemoteChannelSequence == 0 && r.args.unDemoteReleaseSequence == 0 { | ||
return errors.New("one of --channel-sequence or --release-sequence is required") | ||
} | ||
|
||
if r.args.unDemoteChannelSequence != 0 && r.args.unDemoteReleaseSequence != 0 { | ||
fmt.Fprintf(r.w, "Warning: Both --channel-sequence and --release-sequence provided. Using --channel-sequence %d\n", r.args.unDemoteChannelSequence) | ||
} | ||
|
||
chanID := args[0] | ||
|
||
opts := client.GetOrCreateChannelOptions{ | ||
AppID: r.appID, | ||
AppType: r.appType, | ||
NameOrID: chanID, | ||
CreateIfAbsent: false, | ||
} | ||
foundChannel, err := r.api.GetOrCreateChannelByName(opts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
channelSequence := r.args.unDemoteChannelSequence | ||
if r.args.unDemoteReleaseSequence != 0 { | ||
kotsChannel, err := r.api.KotsClient.GetKotsChannel(r.appID, foundChannel.ID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, channelRelease := range kotsChannel.Releases { | ||
if int64(channelRelease.Sequence) == r.args.unDemoteReleaseSequence { | ||
channelSequence = int64(channelRelease.ChannelSequence) | ||
break | ||
} | ||
} | ||
|
||
if channelSequence == 0 { | ||
return fmt.Errorf("release sequence %d not found in channel %s", r.args.unDemoteReleaseSequence, foundChannel.ID) | ||
} | ||
} | ||
|
||
unDemotedRelease, err := r.api.ChannelReleaseUnDemote(r.appID, r.appType, foundChannel.ID, channelSequence) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Fprintf(r.w, "Channel sequence %d (version %s, release %d) un-demoted in channel %s\n", channelSequence, unDemotedRelease.Semver, unDemotedRelease.Sequence, chanID) | ||
r.w.Flush() | ||
|
||
return nil | ||
} |
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -15,17 +15,15 @@ import ( | |
// Runner holds the I/O dependencies and configurations used by individual | ||
// commands, which are defined as methods on this type. | ||
type runners struct { | ||
appID string | ||
appSlug string | ||
appType string | ||
isFoundationApp bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
api client.Client | ||
platformAPI *platformclient.HTTPClient | ||
kotsAPI *kotsclient.VendorV3Client | ||
stdin io.Reader | ||
dir string | ||
outputFormat string | ||
w *tabwriter.Writer | ||
appID string | ||
appSlug string | ||
appType string | ||
api client.Client | ||
platformAPI *platformclient.HTTPClient | ||
kotsAPI *kotsclient.VendorV3Client | ||
stdin io.Reader | ||
outputFormat string | ||
w *tabwriter.Writer | ||
|
||
rootCmd *cobra.Command | ||
args runnerArgs | ||
|
@@ -53,13 +51,7 @@ type runnerArgs struct { | |
createReleaseYamlFile string | ||
createReleaseYamlDir string | ||
createReleaseChart string | ||
createReleaseConfigYaml string | ||
createReleaseDeploymentYaml string | ||
createReleaseServiceYaml string | ||
createReleasePreflightYaml string | ||
createReleaseSupportBundleYaml string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all these where also unused |
||
createReleasePromote string | ||
createReleasePromoteDir string | ||
createReleasePromoteRequired bool | ||
createReleasePromoteNotes string | ||
createReleasePromoteVersion string | ||
|
@@ -177,7 +169,6 @@ type runnerArgs struct { | |
modelCollectionRmModelName string | ||
modelCollectionRmModelCollectionID string | ||
|
||
lsAppVersion string | ||
lsVersionsDistribution string | ||
|
||
lsClusterShowTerminated bool | ||
|
@@ -254,4 +245,9 @@ type runnerArgs struct { | |
clusterAddonCreateObjectStoreDuration time.Duration | ||
clusterAddonCreateObjectStoreDryRun bool | ||
clusterAddonCreateObjectStoreOutput string | ||
|
||
demoteReleaseSequence int64 | ||
demoteChannelSequence int64 | ||
unDemoteReleaseSequence int64 | ||
unDemoteChannelSequence int64 | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused