Skip to content

Commit 923cd44

Browse files
committed
Exchange registry urls
1 parent f4434ef commit 923cd44

5 files changed

Lines changed: 126 additions & 100 deletions

File tree

cmd/add.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func (cmd *AddCmd) RunAddSync(cobraCmd *cobra.Command, args []string) {
345345
}
346346

347347
syncConfig := append(*config.DevSpace.Sync, &v1.SyncConfig{
348-
ResourceType: configutil.String(cmd.syncFlags.ResourceType),
348+
ResourceType: nil,
349349
LabelSelector: &labelSelectorMap,
350350
ContainerPath: configutil.String(cmd.syncFlags.ContainerPath),
351351
LocalSubPath: configutil.String(cmd.syncFlags.LocalPath),
@@ -411,7 +411,7 @@ func (cmd *AddCmd) insertOrReplacePortMapping(labelSelectorMap map[string]*strin
411411
}
412412
}
413413
portMap := append(*config.DevSpace.PortForwarding, &v1.PortForwardingConfig{
414-
ResourceType: configutil.String(cmd.portFlags.ResourceType),
414+
ResourceType: nil,
415415
LabelSelector: &labelSelectorMap,
416416
PortMappings: &portMappings,
417417
})

cmd/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func (cmd *InitCmd) addDefaultSyncConfig() {
266266
syncConfig := append(*config.DevSpace.Sync, &v1.SyncConfig{
267267
ContainerPath: configutil.String("/app"),
268268
LocalSubPath: configutil.String("./"),
269-
ResourceType: configutil.String("pod"),
269+
ResourceType: nil,
270270
LabelSelector: &map[string]*string{
271271
"release": config.DevSpace.Release.Name,
272272
},

cmd/up.go

Lines changed: 5 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cmd
22

33
import (
4-
"fmt"
54
"os"
65
"os/exec"
76
"path/filepath"
@@ -381,6 +380,7 @@ func (cmd *UpCmd) deployChart() {
381380
config := configutil.GetConfig()
382381

383382
log.StartWait("Deploying helm chart")
383+
defer log.StopWait()
384384

385385
releaseName := *config.DevSpace.Release.Name
386386
releaseNamespace := *config.DevSpace.Release.Namespace
@@ -426,81 +426,18 @@ func (cmd *UpCmd) deployChart() {
426426
overwriteValues["pullSecrets"] = pullSecrets
427427

428428
appRelease, err := cmd.helm.InstallChartByPath(releaseName, releaseNamespace, chartPath, &overwriteValues)
429-
430-
log.StopWait()
431-
432429
if err != nil {
433430
log.Fatalf("Unable to deploy helm chart: %s", err.Error())
434431
}
435432

436433
releaseRevision := int(appRelease.Version)
437434
log.Donef("Deployed helm chart (Release revision: %d)", releaseRevision)
438435
log.StartWait("Waiting for release pod to become ready")
439-
defer log.StopWait()
440-
441-
for true {
442-
podList, err := cmd.kubectl.Core().Pods(releaseNamespace).List(metav1.ListOptions{
443-
LabelSelector: "release=" + releaseName,
444-
})
445-
446-
if err != nil {
447-
log.Panicf("Unable to list devspace pods: %s", err.Error())
448-
}
449-
450-
if len(podList.Items) > 0 {
451-
highestRevision := 0
452-
var selectedPod *k8sv1.Pod
453-
454-
for i, pod := range podList.Items {
455-
if kubectl.GetPodStatus(&pod) == "Terminating" {
456-
continue
457-
}
458-
459-
podRevision, podHasRevision := pod.Annotations["revision"]
460-
hasHigherRevision := (i == 0)
461-
462-
if !hasHigherRevision && podHasRevision {
463-
podRevisionInt, _ := strconv.Atoi(podRevision)
464-
465-
if podRevisionInt > highestRevision {
466-
hasHigherRevision = true
467-
}
468-
}
469-
470-
if hasHigherRevision {
471-
selectedPod = &pod
472-
highestRevision, _ = strconv.Atoi(podRevision)
473-
}
474-
}
475-
476-
if selectedPod != nil {
477-
_, hasRevision := selectedPod.Annotations["revision"]
478436

479-
if !hasRevision || highestRevision == releaseRevision {
480-
if !hasRevision {
481-
log.Warn("Found pod without revision. Use annotation 'revision' for your pods to avoid this warning.")
482-
}
483-
484-
cmd.pod = selectedPod
485-
err = waitForPodReady(cmd.kubectl, cmd.pod, 2*60*time.Second, 5*time.Second)
486-
487-
if err != nil {
488-
log.Fatalf("Error during waiting for pod: %s", err.Error())
489-
}
490-
491-
break
492-
} else {
493-
log.Info("Waiting for release upgrade to complete.")
494-
}
495-
}
496-
} else {
497-
log.Info("Waiting for release to be deployed.")
498-
}
499-
500-
time.Sleep(2 * time.Second)
437+
cmd.pod, err = helmClient.WaitForReleasePodToGetReady(cmd.kubectl, releaseName, releaseNamespace, releaseRevision)
438+
if err != nil {
439+
log.Fatal(err)
501440
}
502-
503-
log.StopWait()
504441
}
505442

506443
func (cmd *UpCmd) startSync() []*synctool.SyncConfig {
@@ -592,7 +529,7 @@ func (cmd *UpCmd) startPortForwarding() {
592529
config := configutil.GetConfig()
593530

594531
for _, portForwarding := range *config.DevSpace.PortForwarding {
595-
if *portForwarding.ResourceType == "pod" {
532+
if portForwarding.ResourceType == nil || *portForwarding.ResourceType == "pod" {
596533
if len(*portForwarding.LabelSelector) > 0 {
597534
labels := make([]string, 0, len(*portForwarding.LabelSelector))
598535

@@ -634,22 +571,3 @@ func (cmd *UpCmd) startPortForwarding() {
634571
}
635572
}
636573
}
637-
638-
func waitForPodReady(kubectl *kubernetes.Clientset, pod *k8sv1.Pod, maxWaitTime time.Duration, checkInterval time.Duration) error {
639-
for maxWaitTime > 0 {
640-
pod, err := kubectl.Core().Pods(pod.Namespace).Get(pod.Name, metav1.GetOptions{})
641-
642-
if err != nil {
643-
return err
644-
}
645-
646-
if len(pod.Status.ContainerStatuses) > 0 && pod.Status.ContainerStatuses[0].Ready {
647-
return nil
648-
}
649-
650-
time.Sleep(checkInterval)
651-
maxWaitTime = maxWaitTime - checkInterval
652-
}
653-
654-
return fmt.Errorf("Max wait time expired")
655-
}

pkg/devspace/deploy/helm/deploy.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package helm
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
"time"
7+
8+
k8sv1 "k8s.io/api/core/v1"
9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
"k8s.io/client-go/kubernetes"
11+
12+
"github.com/covexo/devspace/pkg/devspace/kubectl"
13+
"github.com/covexo/devspace/pkg/util/log"
14+
)
15+
16+
// WaitForReleasePodToGetReady waits for the release pod to get ready
17+
func WaitForReleasePodToGetReady(client *kubernetes.Clientset, releaseName, releaseNamespace string, releaseRevision int) (*k8sv1.Pod, error) {
18+
for true {
19+
podList, err := client.Core().Pods(releaseNamespace).List(metav1.ListOptions{
20+
LabelSelector: "release=" + releaseName,
21+
})
22+
23+
if err != nil {
24+
log.Panicf("Unable to list devspace pods: %s", err.Error())
25+
}
26+
27+
if len(podList.Items) > 0 {
28+
highestRevision := 0
29+
var selectedPod *k8sv1.Pod
30+
31+
for i, pod := range podList.Items {
32+
if kubectl.GetPodStatus(&pod) == "Terminating" {
33+
continue
34+
}
35+
36+
podRevision, podHasRevision := pod.Annotations["revision"]
37+
hasHigherRevision := (i == 0)
38+
39+
if !hasHigherRevision && podHasRevision {
40+
podRevisionInt, _ := strconv.Atoi(podRevision)
41+
42+
if podRevisionInt > highestRevision {
43+
hasHigherRevision = true
44+
}
45+
}
46+
47+
if hasHigherRevision {
48+
selectedPod = &pod
49+
highestRevision, _ = strconv.Atoi(podRevision)
50+
}
51+
}
52+
53+
if selectedPod != nil {
54+
_, hasRevision := selectedPod.Annotations["revision"]
55+
56+
if !hasRevision || highestRevision == releaseRevision {
57+
if !hasRevision {
58+
log.Warn("Found pod without revision. Use annotation 'revision' for your pods to avoid this warning.")
59+
}
60+
61+
err = waitForPodReady(client, selectedPod, 2*60*time.Second, 5*time.Second)
62+
if err != nil {
63+
return nil, fmt.Errorf("Error during waiting for pod: %s", err.Error())
64+
}
65+
66+
return selectedPod, nil
67+
}
68+
69+
log.Info("Waiting for release upgrade to complete.")
70+
}
71+
} else {
72+
log.Info("Waiting for release to be deployed.")
73+
}
74+
75+
time.Sleep(2 * time.Second)
76+
}
77+
78+
log.StopWait()
79+
80+
return nil, nil
81+
}
82+
83+
func waitForPodReady(kubectl *kubernetes.Clientset, pod *k8sv1.Pod, maxWaitTime time.Duration, checkInterval time.Duration) error {
84+
for maxWaitTime > 0 {
85+
pod, err := kubectl.Core().Pods(pod.Namespace).Get(pod.Name, metav1.GetOptions{})
86+
87+
if err != nil {
88+
return err
89+
}
90+
91+
if len(pod.Status.ContainerStatuses) > 0 && pod.Status.ContainerStatuses[0].Ready {
92+
return nil
93+
}
94+
95+
time.Sleep(checkInterval)
96+
maxWaitTime = maxWaitTime - checkInterval
97+
}
98+
99+
return fmt.Errorf("Max wait time expired")
100+
}

pkg/devspace/registry/registry.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"time"
1010

11+
"github.com/covexo/devspace/pkg/devspace/config/generated"
1112
"github.com/covexo/devspace/pkg/devspace/config/v1"
1213

1314
"github.com/covexo/devspace/pkg/util/log"
@@ -128,22 +129,29 @@ func waitForRegistry(registryNamespace, registryReleaseDeploymentName string, cl
128129
}
129130

130131
// GetImageURL returns the image (optional with tag)
131-
func GetImageURL(imageConfig *v1.ImageConfig, includingLatestTag bool) string {
132-
registryConfig, registryConfErr := GetRegistryConfig(imageConfig)
133-
134-
if registryConfErr != nil {
135-
log.Fatal(registryConfErr)
136-
}
132+
func GetImageURL(imageName string, generatedConfig *generated.Config, imageConfig *v1.ImageConfig, includingLatestTag bool) string {
137133
image := *imageConfig.Name
138-
registryURL := *registryConfig.URL
139134

140-
if registryURL != "" && registryURL != "hub.docker.com" {
141-
image = registryURL + "/" + image
135+
if imageConfig.Registry != nil {
136+
registryConfig, registryConfErr := GetRegistryConfig(imageConfig)
137+
if registryConfErr != nil {
138+
log.Fatal(registryConfErr)
139+
}
140+
141+
registryURL := *registryConfig.URL
142+
if registryURL != "" && registryURL != "hub.docker.com" {
143+
image = registryURL + "/" + image
144+
}
142145
}
143146

144147
if includingLatestTag {
145-
image = image + ":" + *imageConfig.Tag
148+
if imageConfig.Tag != nil {
149+
image = image + ":" + *imageConfig.Tag
150+
} else {
151+
image = image + ":" + generatedConfig.ImageTags[imageName]
152+
}
146153
}
154+
147155
return image
148156
}
149157

0 commit comments

Comments
 (0)