Skip to content

Commit

Permalink
Updates to platform deployment using CLI. (#423)
Browse files Browse the repository at this point in the history
* Portal credentials/clients settings not passed through.

* Rename CLI commands for deploying Educates platform.

* Updating naming for makefile targets to install platform in local cluster.

* Add distinct platform delete command.

* Remove unnecessary options for delete.

* Create means to get true default installation config.
  • Loading branch information
GrahamDumpleton authored Jun 11, 2024
1 parent 0043a7a commit 805b406
Show file tree
Hide file tree
Showing 17 changed files with 157 additions and 44 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ push-installer-bundle:
ytt -f carvel-packages/installer/bundle --data-values-schema-inspect -o openapi-v3 > developer-testing/educates-training-platform-schema-openapi.yaml
ytt -f carvel-packages/installer/config/package.yaml -f carvel-packages/installer/config/schema.yaml -v imageRegistry.host=$(IMAGE_REPOSITORY) -v version=$(RELEASE_VERSION) -v releasedAt=`date -u +"%Y-%m-%dT%H:%M:%SZ"` --data-value-file openapi=developer-testing/educates-training-platform-schema-openapi.yaml > developer-testing/educates-installer.yaml

deploy-installer:
deploy-platform:
ifneq ("$(wildcard developer-testing/educates-installer-values.yaml)","")
-kubectl create ns educates-installer
ytt --file carvel-packages/installer/bundle/config --data-values-file developer-testing/educates-installer-values.yaml | kapp deploy -a label:installer=educates-installer.app -n educates-installer -f - -y
Expand All @@ -158,11 +158,11 @@ else
ytt --file carvel-packages/installer/bundle/config | kapp deploy -a label:installer=educates-installer.app -n educates-installer -f - -y
endif

delete-installer:
delete-platform:
kapp delete -a educates-installer -y
-kubectl delete ns educates-installer

deploy-installer-bundle: push-installer-bundle
deploy-platform-bundle: push-installer-bundle
kubectl get ns/educates-package || kubectl create ns educates-package
kubectl apply --namespace educates-package -f carvel-packages/installer/config/metadata.yaml
kubectl apply --namespace educates-package -f developer-testing/educates-installer.yaml
Expand All @@ -172,7 +172,7 @@ else
kctrl package install --namespace educates-package --package-install educates-installer --package installer.educates.dev --version $(RELEASE_VERSION)
endif

delete-installer-bundle:
delete-platform-bundle:
kctrl package installed delete --namespace educates-package --package-install educates-installer -y

restart-training-platform:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ trainingPortal:
username: #@ data.values.trainingPortal.credentials.admin.username
#@ if/end hasattr(data.values.trainingPortal.credentials.admin, "password") and data.values.trainingPortal.credentials.admin.password != None:
password: #@ data.values.trainingPortal.credentials.admin.password
#@ if/end hasattr(data.values.trainingPortal.credentials, "admin") and data.values.trainingPortal.credentials.admin != None:
#@ if/end hasattr(data.values.trainingPortal.credentials, "robot") and data.values.trainingPortal.credentials.robot != None:
robot:
#@ if/end hasattr(data.values.trainingPortal.credentials.robot, "username") and data.values.trainingPortal.credentials.robot.username != None:
username: #@ data.values.trainingPortal.credentials.robot.username
#@ if/end hasattr(data.values.trainingPortal.credentials.robot, "password") and data.values.trainingPortal.credentials.robot.password != None:
password: #@ data.values.trainingPortal.credentials.robot.password
#@ if/end hasattr(data.values.trainingPortal, "clients") and data.values.trainingPortal.clients != None:
clients:
#@ if/end hasattr(data.values.trainingPortal.clients, "admin") and data.values.trainingPortal.clients.admin != None:
#@ if/end hasattr(data.values.trainingPortal.clients, "robot") and data.values.trainingPortal.clients.robot != None:
robot:
#@ if/end hasattr(data.values.trainingPortal.clients.robot, "id") and data.values.trainingPortal.clients.robot.id != None:
id: #@ data.values.trainingPortal.clients.robot.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ trainingPortal:
username: #@ data.values.trainingPortal.credentials.admin.username
#@ if/end hasattr(data.values.trainingPortal.credentials.admin, "password") and data.values.trainingPortal.credentials.admin.password != None:
password: #@ data.values.trainingPortal.credentials.admin.password
#@ if/end hasattr(data.values.trainingPortal.credentials, "admin") and data.values.trainingPortal.credentials.admin != None:
#@ if/end hasattr(data.values.trainingPortal.credentials, "robot") and data.values.trainingPortal.credentials.robot != None:
robot:
#@ if/end hasattr(data.values.trainingPortal.credentials.robot, "username") and data.values.trainingPortal.credentials.robot.username != None:
username: #@ data.values.trainingPortal.credentials.robot.username
#@ if/end hasattr(data.values.trainingPortal.credentials.robot, "password") and data.values.trainingPortal.credentials.robot.password != None:
password: #@ data.values.trainingPortal.credentials.robot.password
#@ if/end hasattr(data.values.trainingPortal, "clients") and data.values.trainingPortal.clients != None:
clients:
#@ if/end hasattr(data.values.trainingPortal.clients, "admin") and data.values.trainingPortal.clients.admin != None:
#@ if/end hasattr(data.values.trainingPortal.clients, "robot") and data.values.trainingPortal.clients.robot != None:
robot:
#@ if/end hasattr(data.values.trainingPortal.clients.robot, "id") and data.values.trainingPortal.clients.robot.id != None:
id: #@ data.values.trainingPortal.clients.robot.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ trainingPortal:
username: #@ data.values.trainingPortal.credentials.admin.username
#@ if/end hasattr(data.values.trainingPortal.credentials.admin, "password") and data.values.trainingPortal.credentials.admin.password != None:
password: #@ data.values.trainingPortal.credentials.admin.password
#@ if/end hasattr(data.values.trainingPortal.credentials, "admin") and data.values.trainingPortal.credentials.admin != None:
#@ if/end hasattr(data.values.trainingPortal.credentials, "robot") and data.values.trainingPortal.credentials.robot != None:
robot:
#@ if/end hasattr(data.values.trainingPortal.credentials.robot, "username") and data.values.trainingPortal.credentials.robot.username != None:
username: #@ data.values.trainingPortal.credentials.robot.username
#@ if/end hasattr(data.values.trainingPortal.credentials.robot, "password") and data.values.trainingPortal.credentials.robot.password != None:
password: #@ data.values.trainingPortal.credentials.robot.password
#@ if/end hasattr(data.values.trainingPortal, "clients") and data.values.trainingPortal.clients != None:
clients:
#@ if/end hasattr(data.values.trainingPortal.clients, "admin") and data.values.trainingPortal.clients.admin != None:
#@ if/end hasattr(data.values.trainingPortal.clients, "robot") and data.values.trainingPortal.clients.robot != None:
robot:
#@ if/end hasattr(data.values.trainingPortal.clients.robot, "id") and data.values.trainingPortal.clients.robot.id != None:
id: #@ data.values.trainingPortal.clients.robot.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ trainingPortal:
username: #@ data.values.trainingPortal.credentials.admin.username
#@ if/end hasattr(data.values.trainingPortal.credentials.admin, "password") and data.values.trainingPortal.credentials.admin.password != None:
password: #@ data.values.trainingPortal.credentials.admin.password
#@ if/end hasattr(data.values.trainingPortal.credentials, "admin") and data.values.trainingPortal.credentials.admin != None:
#@ if/end hasattr(data.values.trainingPortal.credentials, "robot") and data.values.trainingPortal.credentials.robot != None:
robot:
#@ if/end hasattr(data.values.trainingPortal.credentials.robot, "username") and data.values.trainingPortal.credentials.robot.username != None:
username: #@ data.values.trainingPortal.credentials.robot.username
#@ if/end hasattr(data.values.trainingPortal.credentials.robot, "password") and data.values.trainingPortal.credentials.robot.password != None:
password: #@ data.values.trainingPortal.credentials.robot.password
#@ if/end hasattr(data.values.trainingPortal, "clients") and data.values.trainingPortal.clients != None:
clients:
#@ if/end hasattr(data.values.trainingPortal.clients, "admin") and data.values.trainingPortal.clients.admin != None:
#@ if/end hasattr(data.values.trainingPortal.clients, "robot") and data.values.trainingPortal.clients.robot != None:
robot:
#@ if/end hasattr(data.values.trainingPortal.clients.robot, "id") and data.values.trainingPortal.clients.robot.id != None:
id: #@ data.values.trainingPortal.clients.robot.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ trainingPortal:
username: #@ data.values.trainingPortal.credentials.admin.username
#@ if/end hasattr(data.values.trainingPortal.credentials.admin, "password") and data.values.trainingPortal.credentials.admin.password != None:
password: #@ data.values.trainingPortal.credentials.admin.password
#@ if/end hasattr(data.values.trainingPortal.credentials, "admin") and data.values.trainingPortal.credentials.admin != None:
#@ if/end hasattr(data.values.trainingPortal.credentials, "robot") and data.values.trainingPortal.credentials.admin != None:
robot:
#@ if/end hasattr(data.values.trainingPortal.credentials.robot, "username") and data.values.trainingPortal.credentials.robot.username != None:
username: #@ data.values.trainingPortal.credentials.robot.username
#@ if/end hasattr(data.values.trainingPortal.credentials.robot, "password") and data.values.trainingPortal.credentials.robot.password != None:
password: #@ data.values.trainingPortal.credentials.robot.password
#@ if/end hasattr(data.values.trainingPortal, "clients") and data.values.trainingPortal.clients != None:
clients:
#@ if/end hasattr(data.values.trainingPortal.clients, "admin") and data.values.trainingPortal.clients.admin != None:
#@ if/end hasattr(data.values.trainingPortal.clients, "robot") and data.values.trainingPortal.clients.robot != None:
robot:
#@ if/end hasattr(data.values.trainingPortal.clients.robot, "id") and data.values.trainingPortal.clients.robot.id != None:
id: #@ data.values.trainingPortal.clients.robot.id
Expand Down
1 change: 0 additions & 1 deletion client-programs/pkg/cmd/admin_cluster_cmd_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func (p *ProjectInfo) NewAdminClusterCmdGroup() *cobra.Command {
p.NewAdminClusterStopCmd(),
p.NewAdminClusterDeleteCmd(),
p.NewAdminClusterStatusCmd(),
p.NewAdminClusterInstallCmd(),
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion client-programs/pkg/cmd/admin_cluster_create_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (o *AdminClusterCreateOptions) Run() error {
var err error = nil

if o.Config == "" {
fullConfig, err = config.NewDefaultInstallationConfig()
fullConfig, err = config.NewInstallationConfigFromUserFile()
} else {
fullConfig, err = config.NewInstallationConfigFromFile(o.Config)
}
Expand Down
1 change: 1 addition & 0 deletions client-programs/pkg/cmd/admin_cmd_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func (p *ProjectInfo) NewAdminCmdGroup() *cobra.Command {
Message: "Available Commands:",
Commands: []*cobra.Command{
p.NewAdminClusterCmdGroup(),
p.NewAdminPlatformCmdGroup(),
p.NewAdminConfigCmdGroup(),
p.NewAdminSecretsCmdGroup(),
p.NewAdminRegistryCmdGroup(),
Expand Down
2 changes: 1 addition & 1 deletion client-programs/pkg/cmd/admin_config_view_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (o *AdminConfigViewOptions) Run() error {
if o.Config != "" {
fullConfig, err = config.NewInstallationConfigFromFile(o.Config)
} else {
fullConfig, err = config.NewDefaultInstallationConfig()
fullConfig, err = config.NewInstallationConfigFromUserFile()
}

if err != nil {
Expand Down
33 changes: 33 additions & 0 deletions client-programs/pkg/cmd/admin_platform_cmd_group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cmd

import (
"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/util/templates"
)

func (p *ProjectInfo) NewAdminPlatformCmdGroup() *cobra.Command {
var c = &cobra.Command{
Use: "platform",
Short: "Manage Educates installation",
}

// Use a command group as it allows us to dictate the order in which they
// are displayed in the help message, as otherwise they are displayed in
// sort order.

commandGroups := templates.CommandGroups{
{
Message: "Available Commands:",
Commands: []*cobra.Command{
p.NewAdminPlatformDeployCmd(),
p.NewAdminPlatformDeleteCmd(),
},
},
}

commandGroups.Add(c)

templates.ActsAsRootCommand(c, []string{"--help"}, commandGroups...)

return c
}
69 changes: 69 additions & 0 deletions client-programs/pkg/cmd/admin_platform_delete_cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package cmd

import (
"fmt"

"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/vmware-tanzu-labs/educates-training-platform/client-programs/pkg/cluster"
"github.com/vmware-tanzu-labs/educates-training-platform/client-programs/pkg/config"
"github.com/vmware-tanzu-labs/educates-training-platform/client-programs/pkg/installer"
)

type PlatformDeleteOptions struct {
KubeconfigOptions
Verbose bool
}

func (o *PlatformDeleteOptions) Run() error {
fullConfig := config.NewDefaultInstallationConfig()

installer := installer.NewInstaller()

clusterConfig := cluster.NewClusterConfig(o.Kubeconfig, o.Context)

err := installer.Delete(fullConfig, clusterConfig, o.Verbose)

if err != nil {
return errors.Wrap(err, "educates could not be deleted")
}

fmt.Println("\nEducates has been deleted succesfully")

return nil
}

func (p *ProjectInfo) NewAdminPlatformDeleteCmd() *cobra.Command {
var o PlatformDeleteOptions

var c = &cobra.Command{
Args: cobra.NoArgs,
Use: "delete",
Short: "Delete Educates and related cluster services from your cluster",
RunE: func(cmd *cobra.Command, _ []string) error {
return o.Run()
},
}

c.Flags().StringVar(
&o.Kubeconfig,
"kubeconfig",
"",
"kubeconfig file to use instead of $KUBECONFIG or $HOME/.kube/config",
)
c.Flags().StringVar(
&o.Context,
"context",
"",
"Context to use from Kubeconfig",
)
c.Flags().BoolVar(
&o.Verbose,
"verbose",
false,
"print verbose output",
)

return c
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,43 @@ import (
var (
installExample = `
# Install educates
educates admin cluster install --config config.yaml
educates admin platform deploy --config config.yaml
# Get default configuration for a specific provider
educates admin cluster install --provider kind --show-packages-values
educates admin platform deploy --provider kind --show-packages-values
# Get default configuration for a specific provider with provided config file
educates admin cluster install --config config.yaml --show-packages-values
educates admin platform deploy --config config.yaml --show-packages-values
# Get deployment descriptors for a specific provider with default config
educates admin cluster install --provider kind --dry-run
educates admin platform deploy --provider kind --dry-run
# Get deployment descriptors for a specific provider with provided config
educates admin cluster install --config config.yaml --dry-run
educates admin platform deploy --config config.yaml --dry-run
# Install educates with verbose output
educates admin cluster install --config config.yaml --verbose
educates admin platform deploy --config config.yaml --verbose
# Install educates without resolving images via kbld (using latest images)
educates admin cluster install --config config.yaml --skip-image-resolution
educates admin platform deploy --config config.yaml --skip-image-resolution
# Install educates showing the differences to be applied to the cluster
educates admin cluster install --config config.yaml --show-diff
educates admin platform deploy --config config.yaml --show-diff
# Install educates with bundle from different repository
educates admin cluster install --config config.yaml --package-repository ghcr.io/jorgemoralespou --version installer-clean
educates admin platform deploy --config config.yaml --package-repository ghcr.io/jorgemoralespou --version installer-clean
# Install educates when locally built
educates admin cluster install --config config.yaml --package-repository localhost:5001 --version 0.0.1
educates admin platform deploy --config config.yaml --package-repository localhost:5001 --version 0.0.1
# Install educates on a specific cluster
educates admin cluster install --config config.yaml --kubeconfig /path/to/kubeconfig --context my-cluster
educates admin cluster install --config config.yaml --kubeconfig /path/to/kubeconfig
educates admin cluster install --config config.yaml --context my-cluster
educates admin platform deploy --config config.yaml --kubeconfig /path/to/kubeconfig --context my-cluster
educates admin platform deploy --config config.yaml --kubeconfig /path/to/kubeconfig
educates admin platform deploy --config config.yaml --context my-cluster
`
)

type AdminInstallOptions struct {
type PlatformDeployOptions struct {
KubeconfigOptions
Delete bool
Config string
Expand All @@ -67,7 +67,7 @@ type AdminInstallOptions struct {
showDiff bool
}

func (o *AdminInstallOptions) Run() error {
func (o *PlatformDeployOptions) Run() error {
fullConfig, err := config.NewInstallationConfigFromFile(o.Config)

if err != nil {
Expand Down Expand Up @@ -171,12 +171,12 @@ func validateProvider(provider string) error {
}
}

func (p *ProjectInfo) NewAdminClusterInstallCmd() *cobra.Command {
var o AdminInstallOptions
func (p *ProjectInfo) NewAdminPlatformDeployCmd() *cobra.Command {
var o PlatformDeployOptions

var c = &cobra.Command{
Args: cobra.NoArgs,
Use: "install",
Use: "deploy",
Short: "Install Educates and related cluster services onto your cluster in an imperative manner",
RunE: func(cmd *cobra.Command, _ []string) error {
// We set the default of skipImageResolution to true if ShowPackagesValues is set and the user has not explicitly set it
Expand Down
2 changes: 1 addition & 1 deletion client-programs/pkg/cmd/admin_resolver_deploy_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (o *AdminResolverDeployOptions) Run() error {
if o.Config != "" {
fullConfig, err = config.NewInstallationConfigFromFile(o.Config)
} else {
fullConfig, err = config.NewDefaultInstallationConfig()
fullConfig, err = config.NewInstallationConfigFromUserFile()
}

if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion client-programs/pkg/cmd/educates_cmd_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func (p *ProjectInfo) NewEducatesCmdGroup() *cobra.Command {
Commands: []*cobra.Command{
overrideCommandName(p.NewAdminClusterCreateCmd(), "create-cluster"),
overrideCommandName(p.NewAdminClusterDeleteCmd(), "delete-cluster"),
overrideCommandName(p.NewAdminClusterInstallCmd(), "install-cluster"),
overrideCommandName(p.NewAdminPlatformDeployCmd(), "deploy-platform"),
overrideCommandName(p.NewAdminPlatformDeleteCmd(), "delete-platform"),
},
},
{
Expand Down
Loading

0 comments on commit 805b406

Please sign in to comment.