Skip to content
Merged
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
2 changes: 1 addition & 1 deletion cli/cmd/channel_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (r *runners) channelInspect(cmd *cobra.Command, args []string) error {
}
chanID := args[0]

appChan, _, err := r.platformAPI.GetChannel(r.appID, chanID)
appChan, _, err := r.api.GetChannel(r.appID, chanID)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/channel_rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (r *runners) channelRemove(cmd *cobra.Command, args []string) error {
}
chanID := args[0]

if err := r.platformAPI.ArchiveChannel(r.appID, chanID); err != nil {
if err := r.api.ArchiveChannel(r.appID, chanID); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion cli/print/channel_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var channelAttrsTmplSrc = `ID: {{ .Id }}
NAME: {{ .Name }}
DESCRIPTION: {{ .Description }}
RELEASE: {{ .ReleaseSequence }}
RELEASE: {{ if ge .ReleaseSequence 1 }}{{ .ReleaseSequence }}{{else}} {{end}}
VERSION: {{ .ReleaseLabel }}
`

Expand Down
33 changes: 30 additions & 3 deletions client/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"errors"

channels "github.com/replicatedhq/replicated/gen/go/v1"
"github.com/replicatedhq/replicated/pkg/types"
)

Expand Down Expand Up @@ -41,12 +42,38 @@ func (c *Client) ListChannels(appID string) ([]types.Channel, error) {
return nil, errors.New("unknown app type")
}

func (c *Client) GetChannel(appID string, channelID string) (interface{}, interface{}, error) {
return nil, nil, nil
func (c *Client) GetChannel(appID string, channelID string) (*channels.AppChannel, []channels.ChannelRelease, error) {
appType, err := c.GetAppType(appID)
if err != nil {
return nil, nil, err
}

if appType == "platform" {
return c.PlatformClient.GetChannel(appID, channelID)
} else if appType == "ship" {
return c.ShipClient.GetChannel(appID, channelID)
} else if appType == "kots" {
return c.KotsClient.GetChannel(appID, channelID)
}
return nil, nil, errors.New("unknown app type")

}

func (c *Client) ArchiveChannel(appID string, channelID string) error {
return nil
appType, err := c.GetAppType(appID)
if err != nil {
return err
}

if appType == "platform" {
return c.PlatformClient.ArchiveChannel(appID, channelID)
} else if appType == "ship" {
return errors.New("This feature is not currently supported for Ship applications.")
} else if appType == "kots" {
return errors.New("This feature is not currently supported for Kots applications.")
}
return errors.New("unknown app type")

}

func (c *Client) CreateChannel(appID string, name string, description string) ([]types.Channel, error) {
Expand Down
94 changes: 89 additions & 5 deletions pkg/kotsclient/channel.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kotsclient

import (
channels "github.com/replicatedhq/replicated/gen/go/v1"
"github.com/replicatedhq/replicated/pkg/graphql"
"github.com/replicatedhq/replicated/pkg/types"
)
Expand All @@ -10,14 +11,23 @@ type GraphQLResponseListChannels struct {
Errors []graphql.GQLError `json:"errors,omitempty"`
}

type GraphQLResponseGetChannel struct {
Data *KotsGetChannelData `json:"data,omitempty"`
Errors []graphql.GQLError `json:"errors,omitempty"`
}
type KotsGetChannelData struct {
KotsChannel *KotsChannel `json:"getKotsChannel"`
}
type KotsChannelData struct {
KotsChannels []*KotsChannel `json:"getKotsAppChannels"`
}

type KotsChannel struct {
ID string `json:"id"`
Name string `json:"name"`
CurrentVersion string `json:"currentVersion"`
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
CurrentSequence int64 `json:"currentSequence"`
CurrentVersion string `json:"currentVersion"`
}

func (c *GraphQLClient) ListChannels(appID string) ([]types.Channel, error) {
Expand Down Expand Up @@ -130,6 +140,80 @@ func ArchiveChannel(appID string, channelID string) error {
return nil
}

func GetChannel(appID string, channelID string) (interface{}, []interface{}, error) {
return nil, nil, nil
var getKotsChannel = `
query getKotsChannel($channelId: ID!) {
getKotsChannel(channelId: $channelId) {
id
appId
name
description
channelIcon
currentVersion
currentReleaseDate
installInstructions
numReleases
adoptionRate {
releaseSequence
semver
count
percent
totalOnChannel
}
customers {
id
name
avatar
actions {
shipApplyDocker
}
installationId
shipInstallStatus {
status
updatedAt
}
}
githubRef {
owner
repoFullName
branch
path
}
extraLintRules
created
updated
isDefault
isArchived
releases {
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to fetch every release on the channel?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dex - see your point, but can we table that for another PR. Currently pulling from what's on Vendorweb.

semver
releaseNotes
created
updated
sequence
airgapBuildStatus
}
}
}
`

func (c *GraphQLClient) GetChannel(appID string, channelID string) (*channels.AppChannel, []channels.ChannelRelease, error) {
response := GraphQLResponseGetChannel{}

request := graphql.Request{
Query: getKotsChannel,
Variables: map[string]interface{}{
"appID": appID,
"channelId": channelID,
},
}
if err := c.ExecuteRequest(request, &response); err != nil {
return nil, nil, err
}

channelDetail := channels.AppChannel{
Id: response.Data.KotsChannel.ID,
Name: response.Data.KotsChannel.Name,
Description: response.Data.KotsChannel.Description,
ReleaseLabel: response.Data.KotsChannel.CurrentVersion,
}
return &channelDetail, nil, nil
}
2 changes: 2 additions & 0 deletions pkg/kotsclient/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kotsclient

import (
channels "github.com/replicatedhq/replicated/gen/go/v1"
"github.com/replicatedhq/replicated/pkg/graphql"
"github.com/replicatedhq/replicated/pkg/types"
)
Expand All @@ -16,6 +17,7 @@ type Client interface {

ListChannels(string) ([]types.Channel, error)
CreateChannel(string, string, string) error
GetChannel(appID, channelID string) (*channels.AppChannel, []channels.ChannelRelease, error)
}

type AppOptions struct {
Expand Down
90 changes: 88 additions & 2 deletions pkg/shipclient/channel.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package shipclient

import (
channels "github.com/replicatedhq/replicated/gen/go/v1"
"github.com/replicatedhq/replicated/pkg/graphql"
"github.com/replicatedhq/replicated/pkg/types"
)
Expand All @@ -10,6 +11,15 @@ type GraphQLResponseListChannels struct {
Errors []graphql.GQLError `json:"errors,omitempty"`
}

type GraphQLResponseGetChannel struct {
Data *ShipGetChannelData `json:"data,omitempty"`
Errors []graphql.GQLError `json:"errors,omitempty"`
}

type ShipGetChannelData struct {
ShipChannel *ShipChannel `json:"getChannel"`
}

type ShipChannelData struct {
ShipChannels []*ShipChannel `json:"getAppChannels"`
}
Expand Down Expand Up @@ -121,6 +131,82 @@ func ArchiveChannel(appID string, channelID string) error {
return nil
}

func GetChannel(appID string, channelID string) (interface{}, []interface{}, error) {
return nil, nil, nil
var getShipChannel = `
query getChannel($channelId: ID!) {
getChannel(channelId: $channelId) {
id
appId
name
description
channelIcon
currentVersion
currentReleaseDate
installInstructions
currentSpec
numReleases
adoptionRate {
releaseId
semver
count
percent
totalOnChannel
}
customers {
id
name
avatar
actions {
shipApplyDocker
}
installationId
shipInstallStatus {
status
updatedAt
}
}
githubRef {
owner
repoFullName
branch
path
}
extraLintRules
created
updated
isDefault
isArchived
releases {
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above, do for fetching channels, do we need to get every release that was published to the channel?

id
semver
spec
releaseNotes
created
updated
sequence
}
}
}
`

func (c *GraphQLClient) GetChannel(appID string, channelID string) (*channels.AppChannel, []channels.ChannelRelease, error) {
response := GraphQLResponseGetChannel{}

request := graphql.Request{
Query: getShipChannel,
Variables: map[string]interface{}{
"appID": appID,
"channelId": channelID,
},
}
if err := c.ExecuteRequest(request, &response); err != nil {
return nil, nil, err
}

channelDetail := channels.AppChannel{
Id: response.Data.ShipChannel.ID,
Name: response.Data.ShipChannel.Name,
Description: response.Data.ShipChannel.Description,
ReleaseLabel: response.Data.ShipChannel.CurrentVersion,
}
return &channelDetail, nil, nil
}
2 changes: 2 additions & 0 deletions pkg/shipclient/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package shipclient

import (
channels "github.com/replicatedhq/replicated/gen/go/v1"
v1 "github.com/replicatedhq/replicated/gen/go/v1"
"github.com/replicatedhq/replicated/pkg/graphql"
"github.com/replicatedhq/replicated/pkg/types"
Expand All @@ -12,6 +13,7 @@ type Client interface {

ListChannels(string) ([]types.Channel, error)
CreateChannel(string, string, string) error
GetChannel(appID, channelID string) (*channels.AppChannel, []channels.ChannelRelease, error)

ListReleases(appID string) ([]types.ReleaseInfo, error)
CreateRelease(appID string, yaml string) (*types.ReleaseInfo, error)
Expand Down
23 changes: 23 additions & 0 deletions pkg/shipclient/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,31 @@ func (c *GraphQLClient) CreateRelease(appID string, yaml string) (*types.Release
return &releaseInfo, nil
}

var updateShipRelease = `
mutation updateRelease($appId: ID!, $spec: String!, $sequence: Int) {
updateRelease(appId: $appId, spec: $spec, sequence: $sequence) {
id
}
}`

func (c *GraphQLClient) UpdateRelease(appID string, sequence int64, yaml string) error {
response := graphql.ResponseErrorOnly{}

request := graphql.Request{
Query: updateShipRelease,
Variables: map[string]interface{}{
"appId": appID,
"sequence": sequence,
"spec": yaml,
},
}

if err := c.ExecuteRequest(request, &response); err != nil {
return err
}

return nil

}

var promoteShipReleaseQuery = `
Expand Down