forked from kyma-project/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add app push command (kyma-project#2246)
- Loading branch information
Showing
5 changed files
with
187 additions
and
4 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
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,19 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/kyma-project/cli.v3/internal/cmdcommon" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewAppCMD(kymaConfig *cmdcommon.KymaConfig) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "app", | ||
Short: "Manage applications on Kubernetes cluster.", | ||
Long: `Use this command to manage applications on the Kubernetes cluster.`, | ||
DisableFlagsInUseLine: true, | ||
} | ||
|
||
cmd.AddCommand(NewAppPushCMD(kymaConfig)) | ||
|
||
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,54 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/kyma-project/cli.v3/internal/clierror" | ||
"github.com/kyma-project/cli.v3/internal/cmdcommon" | ||
"github.com/kyma-project/cli.v3/internal/kube/resources" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type appPushConfig struct { | ||
*cmdcommon.KymaConfig | ||
|
||
name string | ||
namespace string | ||
image string | ||
// containerPort int | ||
} | ||
|
||
func NewAppPushCMD(kymaConfig *cmdcommon.KymaConfig) *cobra.Command { | ||
config := appPushConfig{ | ||
KymaConfig: kymaConfig, | ||
} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "push", | ||
Short: "Push the application to the Kubernetes cluster.", | ||
Long: "Use this command to push the application to the Kubernetes cluster.", | ||
Run: func(_ *cobra.Command, _ []string) { | ||
clierror.Check(runAppPush(&config)) | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVar(&config.name, "name", "", "Name of the app") | ||
cmd.Flags().StringVar(&config.namespace, "namespace", "default", "Namespace where app should be deployed") | ||
cmd.Flags().StringVar(&config.image, "image", "", "Name of the image to deploy") | ||
// cmd.Flags().IntVar(&config.containerPort, "containerPort", 80, "") | ||
_ = cmd.MarkFlagRequired("name") | ||
_ = cmd.MarkFlagRequired("image") | ||
|
||
return cmd | ||
} | ||
|
||
func runAppPush(cfg *appPushConfig) clierror.Error { | ||
client, clierr := cfg.GetKubeClientWithClierr() | ||
if clierr != nil { | ||
return clierr | ||
} | ||
err := resources.CreateDeployment(cfg.Ctx, client, cfg.name, cfg.namespace, cfg.image) | ||
if err != nil { | ||
return clierror.Wrap(err, clierror.New("failed to create deployment")) | ||
} | ||
|
||
return nil | ||
} |
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