Skip to content

Commit

Permalink
Merge pull request #109 from dexhorthy/fix-for-new-ep
Browse files Browse the repository at this point in the history
fix: kurl installer creation was moved to API side
  • Loading branch information
dexhorthy authored Apr 6, 2020
2 parents b19caa3 + e086c45 commit 75481a0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 61 deletions.
2 changes: 1 addition & 1 deletion cli/cmd/collector_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (r *runners) InitCollectorCreate(parent *cobra.Command) {
cmd.Hidden = true // Not supported in KOTS
parent.AddCommand(cmd)

cmd.Flags().StringVar(&r.args.createCollectorYaml, "yaml", "", "The YAML config for this collector. Use '-' to read from stdin. Cannot be used with the `yaml-file` falg.")
cmd.Flags().StringVar(&r.args.createCollectorYaml, "yaml", "", "The YAML config for this collector. Use '-' to read from stdin. Cannot be used with the `yaml-file` flag.")
cmd.Flags().StringVar(&r.args.createCollectorYamlFile, "yaml-file", "", "The file name with YAML config for this collector. Cannot be used with the `yaml` flag.")
cmd.Flags().StringVar(&r.args.createCollectorName, "name", "", "The name for this collector")

Expand Down
7 changes: 4 additions & 3 deletions cli/cmd/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (

func (r *runners) InitInstallerCommand(parent *cobra.Command) *cobra.Command {
installerCommand := &cobra.Command{
Use: "installer",
Short: "Manage Kubernetes installers",
Long: `The installers command allows vendors to create, display, modify and promote kurl.sh specs for managing the installation of Kubernetes.`,
Use: "installer",
Short: "Manage Kubernetes installers",
Long: `The installers command allows vendors to create, display, modify and promote kurl.sh specs for managing the installation of Kubernetes.`,
SilenceUsage: true,
}
parent.AddCommand(installerCommand)

Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/installer_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (r *runners) InitInstallerCreate(parent *cobra.Command) {

parent.AddCommand(cmd)

cmd.Flags().StringVar(&r.args.createInstallerYaml, "yaml", "", "The YAML config for this installer. Use '-' to read from stdin. Cannot be used with the `yaml-file` falg.")
cmd.Flags().StringVar(&r.args.createInstallerYaml, "yaml", "", "The YAML config for this installer. Use '-' to read from stdin. Cannot be used with the `yaml-file` flag.")
cmd.Flags().StringVar(&r.args.createInstallerYamlFile, "yaml-file", "", "The file name with YAML config for this installer. Cannot be used with the `yaml` flag.")
cmd.Flags().StringVar(&r.args.createInstallerPromote, "promote", "", "Channel name or id to promote this installer to")
cmd.Flags().BoolVar(&r.args.createInstallerPromoteEnsureChannel, "ensure-channel", false, "When used with --promote <channel>, will create the channel if it doesn't exist")
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/release_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (r *runners) InitReleaseCreate(parent *cobra.Command) {

parent.AddCommand(cmd)

cmd.Flags().StringVar(&r.args.createReleaseYaml, "yaml", "", "The YAML config for this release. Use '-' to read from stdin. Cannot be used with the `yaml-file` falg.")
cmd.Flags().StringVar(&r.args.createReleaseYaml, "yaml", "", "The YAML config for this release. Use '-' to read from stdin. Cannot be used with the `yaml-file` flag.")
cmd.Flags().StringVar(&r.args.createReleaseYamlFile, "yaml-file", "", "The file name with YAML config for this release. Cannot be used with the `yaml` flag.")
cmd.Flags().StringVar(&r.args.createReleaseYamlDir, "yaml-dir", "", "The directory containing multiple yamls for a Kots release. Cannot be used with the `yaml` flag.")
cmd.Flags().StringVar(&r.args.createReleasePromote, "promote", "", "Channel name or id to promote this release to")
Expand Down
62 changes: 7 additions & 55 deletions pkg/kotsclient/installer.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package kotsclient

import (
"fmt"
"github.com/pkg/errors"
"github.com/replicatedhq/replicated/pkg/graphql"
"github.com/replicatedhq/replicated/pkg/types"
"io/ioutil"
"net/http"
"strings"
)

const kotsListInstallers = `
Expand Down Expand Up @@ -56,8 +52,8 @@ func (c *GraphQLClient) ListInstallers(appID string) ([]types.InstallerSpec, err
}

const kotsCreateInstaller = `
mutation createKotsAppInstaller($appId: ID!, $kurlInstallerId: ID!, $yaml: String!) {
createKotsAppInstaller(appId: $appId, kurlInstallerId: $kurlInstallerId, yaml: $yaml) {
mutation createKotsAppInstaller($appId: ID!, $yaml: String!) {
createKotsAppInstaller(appId: $appId, yaml: $yaml) {
appId
kurlInstallerId
sequence
Expand All @@ -76,67 +72,23 @@ type CreateInstallerDataWrapper struct {

func (c *GraphQLClient) CreateInstaller(appId string, yaml string) (*types.InstallerSpec, error) {

// post yaml to kurl.sh
installerURL, err := c.CreateKurldotSHInstaller(yaml)
installer, err := c.CreateVendorInstaller(appId, yaml)
if err != nil {
return nil, errors.Wrap(err, "create kurl installer")
}

trimmed := strings.TrimLeft(installerURL, "htps:/")
parts := strings.Split(trimmed, "/")
if len(parts) != 2 {
return nil, errors.Errorf("expected exactly two parts of %q, found %d", trimmed, len(parts))
}

installerKurlHash := parts[1]
installer, err := c.CreateVendorInstaller(appId, yaml, installerKurlHash)
if err != nil {
return nil, errors.Wrapf(err, "create vendor installer for kurl hash %q", installerKurlHash)
return nil, errors.Wrap(err, "create vendor installer")
}

return installer, nil
}

func (c *GraphQLClient) CreateKurldotSHInstaller(yaml string) (string, error) {
bodyReader := strings.NewReader(yaml)

req, err := http.NewRequest("POST", fmt.Sprintf("%s/installer", c.KurlDotSHAddress), bodyReader)
if err != nil {
return "", errors.Wrap(err, "create request")
}

req.Header.Set("Content-Type", "text/yaml")

client := http.DefaultClient

resp, err := client.Do(req)
if err != nil {
return "", errors.Wrap(err, "do request")

}

responseBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", errors.Wrap(err, "read response body")
}

if resp.StatusCode != http.StatusCreated {
return "", fmt.Errorf("unexpected status code %d, body was %s", resp.StatusCode, responseBody)
}

return string(responseBody), nil
}

func (c *GraphQLClient) CreateVendorInstaller(appID string, yaml string, kurlInstallerID string) (*types.InstallerSpec, error) {
func (c *GraphQLClient) CreateVendorInstaller(appID string, yaml string) (*types.InstallerSpec, error) {
response := GraphQLResponseCreateInstaller{}

request := graphql.Request{
Query: kotsCreateInstaller,

Variables: map[string]interface{}{
"appId": appID,
"yaml": yaml,
"kurlInstallerId": kurlInstallerID,
"appId": appID,
"yaml": yaml,
},
}

Expand Down

0 comments on commit 75481a0

Please sign in to comment.