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
13 changes: 8 additions & 5 deletions cmd/enter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ type EnterCmd struct {

// EnterCmdFlags are the flags available for the enter-command
type EnterCmdFlags struct {
container string
service string
namespace string
labelSelector string
container string
}

func init() {
Expand All @@ -28,7 +29,7 @@ func init() {

cobraCmd := &cobra.Command{
Use: "enter",
Short: "Enter your DevSpace",
Short: "Start a new terminal session",
Long: `
#######################################################
################## devspace enter #####################
Expand All @@ -38,17 +39,19 @@ devspace:

devspace enter
devspace enter bash
devspace enter -c myContainer
devspace enter -s my-service
devspace enter -c my-container
devspace enter bash -n my-namespace
devspace enter bash -l release=test
#######################################################`,
Run: cmd.Run,
}
rootCmd.AddCommand(cobraCmd)

cobraCmd.Flags().StringVarP(&cmd.flags.service, "service", "s", "", "Service name to select pod/container for terminal")
cobraCmd.Flags().StringVarP(&cmd.flags.container, "container", "c", "", "Container name within pod where to execute command")
cobraCmd.Flags().StringVarP(&cmd.flags.namespace, "namespace", "n", "", "Namespace where to select pods")
cobraCmd.Flags().StringVarP(&cmd.flags.labelSelector, "label-selector", "l", "", "Comma separated key=value selector list (e.g. release=test)")
cobraCmd.Flags().StringVarP(&cmd.flags.namespace, "namespace", "n", "", "Namespace where to select pods")
}

// Run executes the command logic
Expand All @@ -61,5 +64,5 @@ func (cmd *EnterCmd) Run(cobraCmd *cobra.Command, args []string) {
log.Fatalf("Unable to create new kubectl client: %v", err)
}

services.StartTerminal(cmd.kubectl, cmd.flags.container, cmd.flags.labelSelector, cmd.flags.namespace, args, log.GetInstance())
services.StartTerminal(cmd.kubectl, cmd.flags.service, cmd.flags.container, cmd.flags.labelSelector, cmd.flags.namespace, args, log.GetInstance())
}
25 changes: 17 additions & 8 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func (cmd *InitCmd) Run(cobraCmd *cobra.Command, args []string) {
cmd.configureDevSpace()
}

cmd.addDefaultService()
cmd.addDefaultPorts()
cmd.addDefaultSyncConfig()

Expand Down Expand Up @@ -302,6 +303,18 @@ func (cmd *InitCmd) configureDevSpace() {
config.Cluster.Namespace = namespace
}

func (cmd *InitCmd) addDefaultService() {
config := configutil.GetConfig()
config.DevSpace.Services = &[]*v1.ServiceConfig{
{
Name: configutil.String(configutil.DefaultDevspaceServiceName),
LabelSelector: &map[string]*string{
"devspace": configutil.String("default"),
},
},
}
}

func (cmd *InitCmd) addDefaultPorts() {
dockerfilePath := filepath.Join(cmd.workdir, "Dockerfile")
ports, err := dockerfile.GetPorts(dockerfilePath)
Expand All @@ -324,9 +337,7 @@ func (cmd *InitCmd) addDefaultPorts() {
config := configutil.GetConfig()
config.DevSpace.Ports = &[]*v1.PortForwardingConfig{
{
LabelSelector: &map[string]*string{
"release": configutil.String(configutil.DefaultDevspaceDeploymentName),
},
Service: configutil.String(configutil.DefaultDevspaceServiceName),
PortMappings: &portMappings,
},
}
Expand Down Expand Up @@ -355,11 +366,9 @@ func (cmd *InitCmd) addDefaultSyncConfig() {
}

syncConfig := append(*config.DevSpace.Sync, &v1.SyncConfig{
ContainerPath: configutil.String("/app"),
LocalSubPath: configutil.String("./"),
LabelSelector: &map[string]*string{
"release": configutil.String(configutil.DefaultDevspaceDeploymentName),
},
Service: configutil.String(configutil.DefaultDevspaceServiceName),
ContainerPath: configutil.String("/app"),
LocalSubPath: configutil.String("./"),
UploadExcludePaths: &uploadExcludePaths,
})

Expand Down
119 changes: 100 additions & 19 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,30 @@ func init() {
#######################################################
############### devspace list package #################
#######################################################
Lists the packages that were added to the devspace
Lists the packages that were added to the DevSpace
#######################################################
`,
Args: cobra.NoArgs,
Run: cmd.RunListPackage,
}

listCmd.AddCommand(listPackageCmd)

listServiceCmd := &cobra.Command{
Use: "service",
Short: "Lists all services",
Long: `
#######################################################
############### devspace list service #################
#######################################################
Lists the service that are defined in the DevSpace
#######################################################
`,
Args: cobra.NoArgs,
Run: cmd.RunListService,
}

listCmd.AddCommand(listServiceCmd)
}

// RunListPackage runs the list sync command logic
Expand Down Expand Up @@ -133,6 +149,64 @@ func (cmd *ListCmd) RunListPackage(cobraCmd *cobra.Command, args []string) {
log.PrintTable(headerColumnNames, values)
}

// RunListService runs the list service command logic
func (cmd *ListCmd) RunListService(cobraCmd *cobra.Command, args []string) {
config := configutil.GetConfig()

if len(*config.DevSpace.Services) == 0 {
log.Write("No services are configured. Run `devspace add service` to add new service\n")
return
}

headerColumnNames := []string{
"Name",
"Namespace",
"Type",
"Selector",
"Container",
}

services := make([][]string, 0, len(*config.DevSpace.Services))

// Transform values into string arrays
for _, value := range *config.DevSpace.Services {
selector := ""
for k, v := range *value.LabelSelector {
if len(selector) > 0 {
selector += ", "
}

selector += k + "=" + *v
}

resourceType := "pod"
if value.ResourceType != nil {
resourceType = *value.ResourceType
}

// TODO: should we skip this error?
namespace, _ := configutil.GetDefaultNamespace(config)
if value.Namespace != nil {
namespace = *value.Namespace
}

containerName := ""
if value.ContainerName != nil {
containerName = *value.ContainerName
}

services = append(services, []string{
*value.Name,
namespace,
resourceType,
selector,
containerName,
})
}

log.PrintTable(headerColumnNames, services)
}

// RunListSync runs the list sync command logic
func (cmd *ListCmd) RunListSync(cobraCmd *cobra.Command, args []string) {
config := configutil.GetConfig()
Expand All @@ -143,7 +217,7 @@ func (cmd *ListCmd) RunListSync(cobraCmd *cobra.Command, args []string) {
}

headerColumnNames := []string{
"Type",
"Service",
"Selector",
"Local Path",
"Container Path",
Expand All @@ -154,16 +228,20 @@ func (cmd *ListCmd) RunListSync(cobraCmd *cobra.Command, args []string) {

// Transform values into string arrays
for _, value := range *config.DevSpace.Sync {
service := ""
selector := ""

for k, v := range *value.LabelSelector {
if len(selector) > 0 {
selector += ", "
}
if value.Service != nil {
service = *value.Service
} else {
for k, v := range *value.LabelSelector {
if len(selector) > 0 {
selector += ", "
}

selector += k + "=" + *v
selector += k + "=" + *v
}
}

excludedPaths := ""

if value.ExcludePaths != nil {
Expand All @@ -176,13 +254,8 @@ func (cmd *ListCmd) RunListSync(cobraCmd *cobra.Command, args []string) {
}
}

resourceType := "pod"
if value.ResourceType != nil {
resourceType = *value.ResourceType
}

syncPaths = append(syncPaths, []string{
resourceType,
service,
selector,
*value.LocalSubPath,
*value.ContainerPath,
Expand All @@ -203,6 +276,7 @@ func (cmd *ListCmd) RunListPort(cobraCmd *cobra.Command, args []string) {
}

headerColumnNames := []string{
"Service",
"Type",
"Selector",
"Ports (Local:Remote)",
Expand All @@ -212,13 +286,19 @@ func (cmd *ListCmd) RunListPort(cobraCmd *cobra.Command, args []string) {

// Transform values into string arrays
for _, value := range *config.DevSpace.Ports {
service := ""
selector := ""
for k, v := range *value.LabelSelector {
if len(selector) > 0 {
selector += ", "
}

selector += k + "=" + *v
if value.Service != nil {
service = *value.Service
} else {
for k, v := range *value.LabelSelector {
if len(selector) > 0 {
selector += ", "
}

selector += k + "=" + *v
}
}

portMappings := ""
Expand All @@ -236,6 +316,7 @@ func (cmd *ListCmd) RunListPort(cobraCmd *cobra.Command, args []string) {
}

portForwards = append(portForwards, []string{
service,
resourceType,
selector,
portMappings,
Expand Down
8 changes: 5 additions & 3 deletions cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type UpCmdFlags struct {
switchContext bool
portforwarding bool
verboseSync bool
service string
container string
labelSelector string
namespace string
Expand Down Expand Up @@ -85,15 +86,16 @@ Starts and connects your DevSpace:
cobraCmd.Flags().BoolVar(&cmd.flags.tiller, "tiller", cmd.flags.tiller, "Install/upgrade tiller")
cobraCmd.Flags().BoolVar(&cmd.flags.initRegistries, "init-registries", cmd.flags.initRegistries, "Initialize registries (and install internal one)")
cobraCmd.Flags().BoolVarP(&cmd.flags.build, "build", "b", cmd.flags.build, "Force image build")
cobraCmd.Flags().StringVarP(&cmd.flags.container, "container", "c", cmd.flags.container, "Container name where to open the shell")
cobraCmd.Flags().BoolVar(&cmd.flags.sync, "sync", cmd.flags.sync, "Enable code synchronization")
cobraCmd.Flags().BoolVar(&cmd.flags.verboseSync, "verbose-sync", cmd.flags.verboseSync, "When enabled the sync will log every file change")
cobraCmd.Flags().BoolVar(&cmd.flags.portforwarding, "portforwarding", cmd.flags.portforwarding, "Enable port forwarding")
cobraCmd.Flags().BoolVarP(&cmd.flags.deploy, "deploy", "d", cmd.flags.deploy, "Force chart deployment")
cobraCmd.Flags().BoolVar(&cmd.flags.switchContext, "switch-context", cmd.flags.switchContext, "Switch kubectl context to the devspace context")
cobraCmd.Flags().BoolVar(&cmd.flags.exitAfterDeploy, "exit-after-deploy", cmd.flags.exitAfterDeploy, "Exits the command after building the images and deploying the devspace")
cobraCmd.Flags().StringVarP(&cmd.flags.namespace, "namespace", "n", "", "Namespace where to select pods")
cobraCmd.Flags().StringVarP(&cmd.flags.service, "service", "s", "", "Service name to select pods/container for terminal")
cobraCmd.Flags().StringVarP(&cmd.flags.container, "container", "c", cmd.flags.container, "Container name where to open the shell")
cobraCmd.Flags().StringVarP(&cmd.flags.labelSelector, "label-selector", "l", "", "Comma separated key=value selector list (e.g. release=test)")
cobraCmd.Flags().StringVarP(&cmd.flags.namespace, "namespace", "n", "", "Namespace where to select pods")
cobraCmd.Flags().StringVar(&cmd.flags.config, "config", configutil.ConfigPath, "The devspace config file to load (default: '.devspace/config.yaml'")
}

Expand Down Expand Up @@ -223,5 +225,5 @@ func (cmd *UpCmd) startServices(args []string) {
log.Info("See https://devspace-cloud.com/domain-guide for more information")
}

services.StartTerminal(cmd.kubectl, cmd.flags.container, cmd.flags.labelSelector, cmd.flags.namespace, args, log.GetInstance())
services.StartTerminal(cmd.kubectl, cmd.flags.service, cmd.flags.container, cmd.flags.labelSelector, cmd.flags.namespace, args, log.GetInstance())
}
39 changes: 39 additions & 0 deletions pkg/devspace/config/configutil/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"os"
"sync"

"github.com/juju/errors"

"github.com/covexo/devspace/pkg/util/kubeconfig"
"github.com/covexo/devspace/pkg/util/log"
"k8s.io/client-go/tools/clientcmd"
Expand All @@ -28,6 +30,9 @@ var ConfigPath = DefaultConfigPath
// OverwriteConfigPath specifies where the override.yaml lies
var OverwriteConfigPath = "/.devspace/overwrite.yaml"

// DefaultDevspaceServiceName is the name of the initial default service
const DefaultDevspaceServiceName = "default"

// DefaultDevspaceDeploymentName is the name of the initial default deployment
const DefaultDevspaceDeploymentName = "devspace-default"

Expand Down Expand Up @@ -143,6 +148,18 @@ func SetDefaultsOnce() {
}
}

if config.DevSpace.Services != nil {
for index, serviceConfig := range *config.DevSpace.Services {
if serviceConfig.Name == nil {
log.Fatalf("Error in config: Unnamed service at index %d", index)
}

if serviceConfig.Namespace == nil {
serviceConfig.Namespace = String("")
}
}
}

if config.DevSpace.Sync != nil {
for _, syncPath := range *config.DevSpace.Sync {
if syncPath.Namespace == nil {
Expand Down Expand Up @@ -212,3 +229,25 @@ func GetDefaultNamespace(config *v1.Config) (string, error) {

return "default", nil
}

// GetService returns the service referenced by serviceName
func GetService(serviceName string) (*v1.ServiceConfig, error) {
if config.DevSpace.Services != nil {
for _, service := range *config.DevSpace.Services {
if *service.Name == serviceName {
return service, nil
}
}
}
return nil, errors.New("Unable to find service: " + serviceName)
}

// AddService adds a service to the config
func AddService(service *v1.ServiceConfig) error {
if config.DevSpace.Services == nil {
config.DevSpace.Services = &[]*v1.ServiceConfig{}
}
*config.DevSpace.Services = append(*config.DevSpace.Services, service)

return nil
}
Loading