From a3b4d9473643d1ffba7a5364767562c63afa7874 Mon Sep 17 00:00:00 2001 From: dexhorthy Date: Mon, 30 Mar 2020 18:18:56 -0500 Subject: [PATCH 1/2] fix, kurl creation was moved to API side --- cli/cmd/collector_create.go | 2 +- cli/cmd/installer.go | 1 + cli/cmd/installer_create.go | 2 +- cli/cmd/release_create.go | 2 +- pkg/kotsclient/installer.go | 58 ++++--------------------------------- 5 files changed, 9 insertions(+), 56 deletions(-) diff --git a/cli/cmd/collector_create.go b/cli/cmd/collector_create.go index beba7206b..89c408226 100644 --- a/cli/cmd/collector_create.go +++ b/cli/cmd/collector_create.go @@ -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") diff --git a/cli/cmd/installer.go b/cli/cmd/installer.go index 2abb4ee28..0fc74d084 100644 --- a/cli/cmd/installer.go +++ b/cli/cmd/installer.go @@ -9,6 +9,7 @@ func (r *runners) InitInstallerCommand(parent *cobra.Command) *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.`, + SilenceUsage: true, } parent.AddCommand(installerCommand) diff --git a/cli/cmd/installer_create.go b/cli/cmd/installer_create.go index b08f5ff13..6ba6c7500 100644 --- a/cli/cmd/installer_create.go +++ b/cli/cmd/installer_create.go @@ -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 , will create the channel if it doesn't exist") diff --git a/cli/cmd/release_create.go b/cli/cmd/release_create.go index 6124e532b..0afc36450 100644 --- a/cli/cmd/release_create.go +++ b/cli/cmd/release_create.go @@ -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") diff --git a/pkg/kotsclient/installer.go b/pkg/kotsclient/installer.go index d6d5b56e9..f8a035d6b 100644 --- a/pkg/kotsclient/installer.go +++ b/pkg/kotsclient/installer.go @@ -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 = ` @@ -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 @@ -76,58 +72,15 @@ 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{ @@ -136,7 +89,6 @@ func (c *GraphQLClient) CreateVendorInstaller(appID string, yaml string, kurlIns Variables: map[string]interface{}{ "appId": appID, "yaml": yaml, - "kurlInstallerId": kurlInstallerID, }, } From e086c45eaa4debf56e6c2d20c456a5c2ccfed9fc Mon Sep 17 00:00:00 2001 From: dexhorthy Date: Mon, 30 Mar 2020 18:23:48 -0500 Subject: [PATCH 2/2] fmt --- cli/cmd/installer.go | 8 ++++---- pkg/kotsclient/installer.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/cmd/installer.go b/cli/cmd/installer.go index 0fc74d084..42dfd86c8 100644 --- a/cli/cmd/installer.go +++ b/cli/cmd/installer.go @@ -6,10 +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.`, - SilenceUsage: true, + 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) diff --git a/pkg/kotsclient/installer.go b/pkg/kotsclient/installer.go index f8a035d6b..3e99fae95 100644 --- a/pkg/kotsclient/installer.go +++ b/pkg/kotsclient/installer.go @@ -87,8 +87,8 @@ func (c *GraphQLClient) CreateVendorInstaller(appID string, yaml string) (*types Query: kotsCreateInstaller, Variables: map[string]interface{}{ - "appId": appID, - "yaml": yaml, + "appId": appID, + "yaml": yaml, }, }