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: 13 additions & 0 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package cmd

import (
"github.com/devspace-cloud/devspace/pkg/devspace/analyze"
"github.com/devspace-cloud/devspace/pkg/devspace/cloud"
"github.com/devspace-cloud/devspace/pkg/devspace/config/configutil"
"github.com/devspace-cloud/devspace/pkg/devspace/config/generated"
latest "github.com/devspace-cloud/devspace/pkg/devspace/config/versions/latest"
"github.com/devspace-cloud/devspace/pkg/devspace/kubectl"
"github.com/devspace-cloud/devspace/pkg/util/log"
Expand Down Expand Up @@ -55,6 +57,17 @@ func (cmd *AnalyzeCmd) RunAnalyze(cobraCmd *cobra.Command, args []string) {
var devSpaceConfig *latest.Config
if configExists {
devSpaceConfig = configutil.GetConfig()

generatedConfig, err := generated.LoadConfig()
if err != nil {
log.Fatal(err)
}

// Signal that we are working on the space if there is any
err = cloud.ResumeSpace(devSpaceConfig, generatedConfig, true, log.GetInstance())
if err != nil {
log.Fatal(err)
}
}

// Create kubectl client
Expand Down
7 changes: 7 additions & 0 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"github.com/devspace-cloud/devspace/pkg/devspace/build"
"github.com/devspace-cloud/devspace/pkg/devspace/cloud"
"github.com/devspace-cloud/devspace/pkg/devspace/config/configutil"
"github.com/devspace-cloud/devspace/pkg/devspace/config/generated"
latest "github.com/devspace-cloud/devspace/pkg/devspace/config/versions/latest"
Expand Down Expand Up @@ -99,6 +100,12 @@ func (cmd *DeployCmd) Run(cobraCmd *cobra.Command, args []string) {
// Prepare the config
config := cmd.loadConfig(generatedConfig)

// Signal that we are working on the space if there is any
err = cloud.ResumeSpace(config, generatedConfig, true, log.GetInstance())
if err != nil {
log.Fatal(err)
}

// Create kubectl client
client, err := kubectl.NewClientWithContextSwitch(config, cmd.SwitchContext)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/devspace-cloud/devspace/pkg/devspace/build"
"github.com/devspace-cloud/devspace/pkg/devspace/cloud"
"github.com/devspace-cloud/devspace/pkg/devspace/dependency"
deploy "github.com/devspace-cloud/devspace/pkg/devspace/deploy/util"
"github.com/devspace-cloud/devspace/pkg/devspace/services/targetselector"
Expand Down Expand Up @@ -125,6 +126,12 @@ func (cmd *DevCmd) Run(cobraCmd *cobra.Command, args []string) {
// Get the config
config := cmd.loadConfig(generatedConfig)

// Signal that we are working on the space if there is any
err = cloud.ResumeSpace(config, generatedConfig, true, log.GetInstance())
if err != nil {
log.Fatal(err)
}

// Create kubectl client and switch context if specified
client, err := kubectl.NewClientWithContextSwitch(config, cmd.SwitchContext)
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions cmd/enter.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package cmd

import (
"github.com/devspace-cloud/devspace/pkg/devspace/cloud"
"github.com/devspace-cloud/devspace/pkg/devspace/config/configutil"
"github.com/devspace-cloud/devspace/pkg/devspace/config/generated"
latest "github.com/devspace-cloud/devspace/pkg/devspace/config/versions/latest"
"github.com/devspace-cloud/devspace/pkg/devspace/kubectl"
"github.com/devspace-cloud/devspace/pkg/devspace/services"
"github.com/devspace-cloud/devspace/pkg/devspace/services/targetselector"
"github.com/devspace-cloud/devspace/pkg/util/log"

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -69,6 +72,16 @@ func (cmd *EnterCmd) Run(cobraCmd *cobra.Command, args []string) {
var config *latest.Config
if configutil.ConfigExists() {
config = configutil.GetConfig()

generatedConfig, err := generated.LoadConfig()
if err != nil {
log.Fatal(err)
}

err = cloud.ResumeSpace(config, generatedConfig, true, log.GetInstance())
if err != nil {
log.Fatal(err)
}
}

// Get kubectl client
Expand Down
13 changes: 13 additions & 0 deletions cmd/logs.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cmd

import (
"github.com/devspace-cloud/devspace/pkg/devspace/cloud"
"github.com/devspace-cloud/devspace/pkg/devspace/config/configutil"
"github.com/devspace-cloud/devspace/pkg/devspace/config/generated"
latest "github.com/devspace-cloud/devspace/pkg/devspace/config/versions/latest"
"github.com/devspace-cloud/devspace/pkg/devspace/kubectl"
"github.com/devspace-cloud/devspace/pkg/devspace/services"
Expand Down Expand Up @@ -68,6 +70,17 @@ func (cmd *LogsCmd) RunLogs(cobraCmd *cobra.Command, args []string) {
var config *latest.Config
if configutil.ConfigExists() {
config = configutil.GetConfig()

generatedConfig, err := generated.LoadConfig()
if err != nil {
log.Fatal(err)
}

// Signal that we are working on the space if there is any
err = cloud.ResumeSpace(config, generatedConfig, true, log.GetInstance())
if err != nil {
log.Fatal(err)
}
}

// Get kubectl client
Expand Down
11 changes: 11 additions & 0 deletions cmd/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ func (cmd *OpenCmd) RunOpen(cobraCmd *cobra.Command, args []string) {
var devspaceConfig *latest.Config
if configExists {
devspaceConfig = configutil.GetConfig()

generatedConfig, err := generated.LoadConfig()
if err != nil {
log.Fatal(err)
}

// Signal that we are working on the space if there is any
err = cloud.ResumeSpace(devspaceConfig, generatedConfig, true, log.GetInstance())
if err != nil {
log.Fatal(err)
}
}
namespace, err := configutil.GetDefaultNamespace(devspaceConfig)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions cmd/purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"strings"

"github.com/devspace-cloud/devspace/pkg/devspace/cloud"
"github.com/devspace-cloud/devspace/pkg/devspace/config/configutil"
"github.com/devspace-cloud/devspace/pkg/devspace/config/generated"
latest "github.com/devspace-cloud/devspace/pkg/devspace/config/versions/latest"
Expand Down Expand Up @@ -74,6 +75,12 @@ func (cmd *PurgeCmd) Run(cobraCmd *cobra.Command, args []string) {
// Get the config
config := cmd.loadConfig(generatedConfig)

// Signal that we are working on the space if there is any
err = cloud.ResumeSpace(config, generatedConfig, true, log.GetInstance())
if err != nil {
log.Fatal(err)
}

kubectl, err := kubectl.NewClient(config)
if err != nil {
log.Fatalf("Unable to create new kubectl client: %v", err)
Expand Down
13 changes: 13 additions & 0 deletions cmd/sync.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cmd

import (
"github.com/devspace-cloud/devspace/pkg/devspace/cloud"
"github.com/devspace-cloud/devspace/pkg/devspace/config/configutil"
"github.com/devspace-cloud/devspace/pkg/devspace/config/generated"
latest "github.com/devspace-cloud/devspace/pkg/devspace/config/versions/latest"
"github.com/devspace-cloud/devspace/pkg/devspace/services"
"github.com/devspace-cloud/devspace/pkg/devspace/services/targetselector"
Expand Down Expand Up @@ -67,6 +69,17 @@ func (cmd *SyncCmd) Run(cobraCmd *cobra.Command, args []string) {
var config *latest.Config
if configutil.ConfigExists() {
config = configutil.GetConfig()

generatedConfig, err := generated.LoadConfig()
if err != nil {
log.Fatal(err)
}

// Signal that we are working on the space if there is any
err = cloud.ResumeSpace(config, generatedConfig, true, log.GetInstance())
if err != nil {
log.Fatal(err)
}
}

// Build params
Expand Down
6 changes: 6 additions & 0 deletions cmd/use/space.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ func (cmd *spaceCmd) RunUseSpace(cobraCmd *cobra.Command, args []string) {
if err != nil {
log.Fatal(err)
}

// Signal that we are working on the space if there is any
err = cloud.ResumeSpace(configutil.GetConfig(), generatedConfig, false, log.GetInstance())
if err != nil {
log.Fatal(err)
}
}

log.Donef("Successfully configured config to use space %s", space.Name)
Expand Down
15 changes: 4 additions & 11 deletions pkg/devspace/cloud/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,9 @@ func defaultClusterSpaceDomain(p *Provider, client kubernetes.Interface, useHost
defer log.StopWait()

now := time.Now()
hostname := ""
ip := ""

for time.Since(now) < waitTimeout && hostname == "" && ip == "" {
Outer:
for time.Since(now) < waitTimeout {
// Get loadbalancer
services, err := client.CoreV1().Services(constants.DevSpaceCloudNamespace).List(metav1.ListOptions{})
if err != nil {
Expand All @@ -234,19 +233,13 @@ func defaultClusterSpaceDomain(p *Provider, client kubernetes.Interface, useHost
if service.Spec.Type == v1.ServiceTypeLoadBalancer {
for _, ingress := range service.Status.LoadBalancer.Ingress {
if ingress.Hostname != "" {
hostname = ingress.Hostname
break Outer
}
if ingress.IP != "" {
ip = ingress.IP
break Outer
}

break
}
}

if hostname != "" || ip != "" {
break
}
}

time.Sleep(5 * time.Second)
Expand Down
119 changes: 119 additions & 0 deletions pkg/devspace/cloud/resume.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package cloud

import (
"fmt"
"time"

"github.com/devspace-cloud/devspace/pkg/devspace/config/configutil"
"github.com/devspace-cloud/devspace/pkg/devspace/config/generated"
"github.com/devspace-cloud/devspace/pkg/devspace/config/versions/latest"
"github.com/devspace-cloud/devspace/pkg/devspace/kubectl"
"github.com/devspace-cloud/devspace/pkg/util/log"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/pkg/errors"
)

// ResumeSpace signals the cloud that we are currently working on the space and resumes it if it's currently paused
func ResumeSpace(config *latest.Config, generatedConfig *generated.Config, loop bool, log log.Logger) error {
if generatedConfig.CloudSpace == nil {
return nil
}

p, err := GetProvider(&generatedConfig.CloudSpace.ProviderName, log)
if err != nil {
return err
}

space, err := p.GetSpace(generatedConfig.CloudSpace.SpaceID)
if err != nil {
return fmt.Errorf("Error retrieving Spaces details: %v", err)
}

resumed, err := p.ResumeSpace(space.SpaceID, space.Cluster)
if err != nil {
return errors.Wrap(err, "active space")
}

// We will wait a little bit till the space has resumed
if resumed {
log.StartWait("Resuming space")
defer log.StopWait()

// Give the controllers some time to create the pods
time.Sleep(time.Second * 3)

// Create kubectl client and switch context if specified
client, err := kubectl.NewClient(config)
if err != nil {
return fmt.Errorf("Unable to create new kubectl client: %v", err)
}

namespace, err := configutil.GetDefaultNamespace(config)
if err != nil {
return err
}

maxWait := time.Minute * 5
start := time.Now()

for time.Now().Sub(start) <= maxWait {
pods, err := client.CoreV1().Pods(namespace).List(metav1.ListOptions{})
if err != nil {
return errors.Wrap(err, "list pods")
}

continueWaiting := false
for _, pod := range pods.Items {
for _, containerStatus := range pod.Status.ContainerStatuses {
if containerStatus.State.Waiting != nil {
continueWaiting = true
}
}
}

if !continueWaiting {
break
}

time.Sleep(1 * time.Second)
}
}

if loop {
go func() {
for {
time.Sleep(time.Minute * 3)
p.ResumeSpace(space.SpaceID, space.Cluster)
}
}()
}

return nil
}

// ResumeSpace resumes a space if its sleeping and sets the last activity to the current timestamp
func (p *Provider) ResumeSpace(spaceID int, cluster *Cluster) (bool, error) {
key, err := p.GetClusterKey(cluster)
if err != nil {
return false, errors.Wrap(err, "get cluster key")
}

// Do the request
response := &struct {
ResumeSpace bool `json:"manager_resumeSpace"`
}{}
err = p.GrapqhlRequest(`
mutation ($key:String, $spaceID: Int!){
manager_resumeSpace(key: $key, spaceID: $spaceID)
}
`, map[string]interface{}{
"key": key,
"spaceID": spaceID,
}, response)
if err != nil {
return false, err
}

return response.ResumeSpace, nil
}
9 changes: 4 additions & 5 deletions pkg/devspace/config/versions/latest/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package latest
import (
"github.com/devspace-cloud/devspace/pkg/devspace/config/versions/config"
"github.com/devspace-cloud/devspace/pkg/util/ptr"
v1 "k8s.io/api/core/v1"
)

// Version is the current api version
Expand Down Expand Up @@ -163,10 +162,10 @@ type RollingUpdateConfig struct {

// VolumeConfig holds the configuration for a specific volume
type VolumeConfig struct {
Name *string `yaml:"name,omitempty"`
Size *string `yaml:"size,omitempty"`
ConfigMap *v1.ConfigMapVolumeSource `yaml:"configMap,omitempty"`
Secret *v1.SecretVolumeSource `yaml:"secret,omitempty"`
Name *string `yaml:"name,omitempty"`
Size *string `yaml:"size,omitempty"`
ConfigMap *map[interface{}]interface{} `yaml:"configMap,omitempty"`
Secret *map[interface{}]interface{} `yaml:"secret,omitempty"`
}

// ServiceConfig holds the configuration of a component service
Expand Down