Skip to content

Commit 5cb68b8

Browse files
fixed windows compatiblity bugs and added app-proxy upgrade (#199)
* fixed windows compatiblity bugs and added app-proxy upgrade * removed useless write to file Co-authored-by: roikramer120 <[email protected]>
1 parent 89a4124 commit 5cb68b8

File tree

6 files changed

+145
-29
lines changed

6 files changed

+145
-29
lines changed

venona/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.3
1+
1.5.4

venonactl/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.3
1+
1.5.4

venonactl/cmd/cmdutils.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"io/ioutil"
66
"os"
77
"os/user"
8-
"path"
8+
"path/filepath"
99
"strings"
1010
"time"
1111

@@ -75,9 +75,12 @@ func extendStoreWithCodefershClient(logger logger.Logger) error {
7575
return err
7676
}
7777

78-
configPath := path.Join(currentUser.HomeDir, ".cfconfig")
79-
logger.Debug("cfconfig path not set, using:", "cfconfig", configPath)
78+
configPath = filepath.Join(currentUser.HomeDir, ".cfconfig")
79+
logger.Debug(fmt.Sprint("cfconfig path not set, using: ", configPath))
80+
}
8081

82+
if _, err := os.Stat(configPath); err != nil {
83+
return fmt.Errorf(".cfconfig file not found")
8184
}
8285

8386
if cfAPIHost == "" && cfAPIToken == "" {
@@ -117,7 +120,7 @@ func extendStoreWithKubeClient(logger logger.Logger) {
117120
if kubeConfigPath == "" {
118121
currentUser, _ := user.Current()
119122
if currentUser != nil {
120-
kubeConfigPath = path.Join(currentUser.HomeDir, ".kube", "config")
123+
kubeConfigPath = filepath.Join(currentUser.HomeDir, ".kube", "config")
121124
logger.Debug("Path to kubeconfig not set, using:", "kubeconfig", kubeConfigPath)
122125
}
123126
}

venonactl/cmd/upgrade-app-proxy.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package cmd
2+
3+
/*
4+
Copyright 2019 The Codefresh Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
import (
20+
"github.com/codefresh-io/venona/venonactl/pkg/plugins"
21+
"github.com/codefresh-io/venona/venonactl/pkg/store"
22+
"github.com/spf13/cobra"
23+
"github.com/spf13/viper"
24+
)
25+
26+
var upgradeAppProxyCmdOptions struct {
27+
kube struct {
28+
context string
29+
namespace string
30+
}
31+
templateValues []string
32+
templateFileValues []string
33+
templateValueFiles []string
34+
}
35+
36+
var upgradeAppProxyCmd = &cobra.Command{
37+
Use: "app-proxy",
38+
Short: "Upgrade App proxy",
39+
Run: func(cmd *cobra.Command, args []string) {
40+
41+
templateValuesMap, err := templateValuesToMap(
42+
upgradeAppProxyCmdOptions.templateValueFiles,
43+
upgradeAppProxyCmdOptions.templateValues,
44+
upgradeAppProxyCmdOptions.templateFileValues)
45+
if err != nil {
46+
dieOnError(err)
47+
}
48+
49+
mergeValueStr(templateValuesMap, "ConfigPath", &kubeConfigPath)
50+
mergeValueStr(templateValuesMap, "CodefreshHost", &cfAPIHost)
51+
mergeValueStr(templateValuesMap, "Namespace", &upgradeAppProxyCmdOptions.kube.namespace)
52+
mergeValueStr(templateValuesMap, "Context", &upgradeAppProxyCmdOptions.kube.context)
53+
54+
lgr := createLogger("Upgrade-AppProxy", verbose, logFormatter)
55+
builder := plugins.NewBuilder(lgr)
56+
57+
builder.Add(plugins.AppProxyPluginType)
58+
59+
s := store.GetStore()
60+
buildBasicStore(lgr)
61+
extendStoreWithKubeClient(lgr)
62+
dieOnError(extendStoreWithCodefershClient(lgr))
63+
extendStoreWithAgentAPI(lgr, "", "")
64+
fillKubernetesAPI(lgr, upgradeAppProxyCmdOptions.kube.context, upgradeAppProxyCmdOptions.kube.namespace, false)
65+
values := s.BuildValues()
66+
values = mergeMaps(values, templateValuesMap)
67+
68+
for _, p := range builder.Get() {
69+
values, err = p.Upgrade(&plugins.UpgradeOptions{
70+
Name: store.AppProxyApplicationName,
71+
ClusterNamespace: upgradeAppProxyCmdOptions.kube.namespace,
72+
ClusterName: upgradeAppProxyCmdOptions.kube.namespace,
73+
KubeBuilder: getKubeClientBuilder(upgradeAppProxyCmdOptions.kube.context, upgradeAppProxyCmdOptions.kube.namespace, s.KubernetesAPI.ConfigPath, s.KubernetesAPI.InCluster),
74+
}, values)
75+
if err != nil {
76+
dieOnError(err)
77+
}
78+
}
79+
},
80+
}
81+
82+
func init() {
83+
viper.BindEnv("kube-namespace", "KUBE_NAMESPACE")
84+
viper.BindEnv("kube-context", "KUBE_CONTEXT")
85+
upgradeCmd.AddCommand(upgradeAppProxyCmd)
86+
upgradeAppProxyCmd.Flags().StringVar(&upgradeAppProxyCmdOptions.kube.namespace, "kube-namespace", viper.GetString("kube-namespace"), "Name of the namespace on which venona should be installed [$KUBE_NAMESPACE]")
87+
upgradeAppProxyCmd.Flags().StringVar(&upgradeAppProxyCmdOptions.kube.context, "kube-context-name", viper.GetString("kube-context"), "Name of the kubernetes context on which venona should be installed (default is current-context) [$KUBE_CONTEXT]")
88+
upgradeAppProxyCmd.Flags().StringArrayVarP(&upgradeAppProxyCmdOptions.templateValueFiles, "values", "f", []string{}, "specify values in a YAML file")
89+
upgradeAppProxyCmd.Flags().StringArrayVar(&upgradeAppProxyCmdOptions.templateValues, "set-value", []string{}, "Set values for templates, example: --set-value LocalVolumesDir=/mnt/disks/ssd0/codefresh-volumes")
90+
}

venonactl/cmd/upgrade.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ var upgradeCmd = &cobra.Command{
6060
s := store.GetStore()
6161
buildBasicStore(lgr)
6262
extendStoreWithKubeClient(lgr)
63-
extendStoreWithCodefershClient(lgr)
63+
dieOnError(extendStoreWithCodefershClient(lgr))
6464
extendStoreWithAgentAPI(lgr, "", "")
6565
fillKubernetesAPI(lgr, upgradeCmdOpt.kube.context, upgradeCmdOpt.kube.namespace, false)
6666
values := s.BuildValues()

venonactl/pkg/plugins/app-proxy.go

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
package plugins
22

3+
/*
4+
Copyright 2019 The Codefresh Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
319
import (
4-
"encoding/json"
520
"fmt"
6-
"os"
721

822
"github.com/codefresh-io/venona/venonactl/pkg/logger"
923
templates "github.com/codefresh-io/venona/venonactl/pkg/templates/kubernetes"
1024
"github.com/stretchr/objx"
25+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1126
)
1227

1328
type appProxyPlugin struct {
@@ -49,25 +64,7 @@ func (u *appProxyPlugin) Install(opt *InstallOptions, v Values) (Values, error)
4964
pathPrefix := objx.New(v["AppProxy"]).Get("PathPrefix").Str()
5065
appProxyURL := fmt.Sprintf("https://%v%v", host, pathPrefix)
5166
u.logger.Info(fmt.Sprintf("\napp proxy is running at: %v", appProxyURL))
52-
53-
// update IPC
54-
file := os.NewFile(3, "pipe")
55-
if file == nil {
56-
return v, nil
57-
}
58-
data := map[string]interface{}{
59-
"ingressIP": appProxyURL,
60-
}
61-
var jsonData []byte
62-
jsonData, err = json.Marshal(data)
63-
n, err := file.Write(jsonData)
64-
if err != nil {
65-
u.logger.Error("Failed to write to stream", err)
66-
return v, fmt.Errorf("Failed to write to stream")
67-
}
68-
u.logger.Debug(fmt.Sprintf("%v bytes were written to stream\n", n))
69-
return v, err
70-
67+
return v, nil
7168
}
7269

7370
func (u *appProxyPlugin) Status(statusOpt *StatusOptions, v Values) ([][]string, error) {
@@ -93,7 +90,33 @@ func (u *appProxyPlugin) Delete(deleteOpt *DeleteOptions, v Values) error {
9390
}
9491

9592
func (u *appProxyPlugin) Upgrade(opt *UpgradeOptions, v Values) (Values, error) {
96-
return nil, nil
93+
kubeClientset, err := opt.KubeBuilder.BuildClient()
94+
if err != nil {
95+
u.logger.Error(fmt.Sprintf("Cannot create kubernetes clientset: %v ", err))
96+
return nil, err
97+
}
98+
99+
list, err := kubeClientset.CoreV1().Pods(opt.ClusterNamespace).List(metav1.ListOptions{LabelSelector: fmt.Sprintf("app=%v", opt.Name)})
100+
if err != nil {
101+
u.logger.Error(fmt.Sprintf("Failed to list app-proxy pods: %v ", err))
102+
return nil, err
103+
}
104+
if len(list.Items) == 0 {
105+
u.logger.Info("no app-proxy pods found")
106+
return nil, nil
107+
}
108+
109+
for _, pod := range list.Items {
110+
podName := pod.ObjectMeta.Name
111+
u.logger.Debug(fmt.Sprintf("Deleting app-proxy pod: %v", podName))
112+
err = kubeClientset.CoreV1().Pods(opt.ClusterNamespace).Delete(podName, &metav1.DeleteOptions{})
113+
if err != nil {
114+
u.logger.Error(fmt.Sprintf("Cannot delete app-proxy pod: %v ", err))
115+
return nil, err
116+
}
117+
}
118+
119+
return v, nil
97120
}
98121
func (u *appProxyPlugin) Migrate(*MigrateOptions, Values) error {
99122
return fmt.Errorf("not supported")

0 commit comments

Comments
 (0)