@@ -10,10 +10,11 @@ import (
10
10
"github.com/codefresh-io/go-sdk/pkg/codefresh"
11
11
sdkUtils "github.com/codefresh-io/go-sdk/pkg/utils"
12
12
"github.com/codefresh-io/venona/venonactl/pkg/certs"
13
+ "github.com/codefresh-io/venona/venonactl/pkg/kube"
14
+ "github.com/codefresh-io/venona/venonactl/pkg/logger"
13
15
"github.com/codefresh-io/venona/venonactl/pkg/plugins"
14
16
"github.com/codefresh-io/venona/venonactl/pkg/store"
15
17
"github.com/olekukonko/tablewriter"
16
- "github.com/sirupsen/logrus"
17
18
)
18
19
19
20
var (
36
37
skipVerionCheck bool
37
38
)
38
39
39
- func buildBasicStore () {
40
+ func buildBasicStore (logger logger. Logger ) {
40
41
s := store .GetStore ()
41
42
s .Version = & store.Version {
42
43
Current : & store.CurrentVersion {
@@ -62,13 +63,10 @@ func buildBasicStore() {
62
63
IsDefault : true ,
63
64
}
64
65
s .Version .Latest = latestVersion
65
- logrus .WithFields (logrus.Fields {
66
- "Default-Version" : store .DefaultVersion ,
67
- "Image-Tag" : s .Version .Current .Version ,
68
- }).Debug ("Skipping version check" )
66
+ logger .Debug ("Skipping version check" )
69
67
} else {
70
68
latestVersion := & store.LatestVersion {
71
- Version : store .GetLatestVersion (),
69
+ Version : store .GetLatestVersion (logger ),
72
70
IsDefault : false ,
73
71
}
74
72
s .Image .Tag = latestVersion .Version
@@ -77,15 +75,14 @@ func buildBasicStore() {
77
75
// the local version and the latest version not match
78
76
// make sure the command is no venonactl version
79
77
if ! res {
80
- logrus .WithFields (logrus.Fields {
81
- "Local-Version" : s .Version .Current .Version ,
82
- "Latest-Version" : s .Version .Latest .Version ,
83
- }).Info ("New version is avaliable, please update" )
78
+ logger .Info ("New version is avaliable, please update" ,
79
+ "Local-Version" , s .Version .Current .Version ,
80
+ "Latest-Version" , s .Version .Latest .Version )
84
81
}
85
82
}
86
83
}
87
84
88
- func extendStoreWithCodefershClient () error {
85
+ func extendStoreWithCodefershClient (logger logger. Logger ) error {
89
86
s := store .GetStore ()
90
87
if configPath == "" {
91
88
configPath = fmt .Sprintf ("%s/.cfconfig" , os .Getenv ("HOME" ))
@@ -98,13 +95,9 @@ func extendStoreWithCodefershClient() error {
98
95
}
99
96
cfAPIHost = context .URL
100
97
cfAPIToken = context .Token
101
-
102
- logrus .WithFields (logrus.Fields {
103
- "Context-Name" : context .Name ,
104
- "Codefresh-Host" : cfAPIHost ,
105
- }).Debug ("Using codefresh context" )
98
+ logger .Debug ("Using codefresh context" , "Context-Name" , context .Name , "Host" , cfAPIHost )
106
99
} else {
107
- logrus .Debug ("Using creentials from environment variables" )
100
+ logger .Debug ("Reading creentials from environment variables" )
108
101
}
109
102
110
103
client := codefresh .New (& codefresh.ClientOptions {
@@ -122,15 +115,13 @@ func extendStoreWithCodefershClient() error {
122
115
return nil
123
116
}
124
117
125
- func extendStoreWithKubeClient () {
118
+ func extendStoreWithKubeClient (logger logger. Logger ) {
126
119
s := store .GetStore ()
127
120
if kubeConfigPath == "" {
128
121
currentUser , _ := user .Current ()
129
122
if currentUser != nil {
130
123
kubeConfigPath = path .Join (currentUser .HomeDir , ".kube" , "config" )
131
- logrus .WithFields (logrus.Fields {
132
- "Kube-Config-Path" : kubeConfigPath ,
133
- }).Debug ("Path to kubeconfig not set, using default" )
124
+ logger .Debug ("Path to kubeconfig not set, using default" )
134
125
}
135
126
}
136
127
@@ -139,12 +130,6 @@ func extendStoreWithKubeClient() {
139
130
}
140
131
}
141
132
142
- func prepareLogger () {
143
- if verbose == true {
144
- logrus .SetLevel (logrus .DebugLevel )
145
- }
146
- }
147
-
148
133
func isUsingDefaultStorageClass (sc string ) bool {
149
134
if sc == "" {
150
135
return true
@@ -154,7 +139,7 @@ func isUsingDefaultStorageClass(sc string) bool {
154
139
155
140
func dieOnError (err error ) {
156
141
if err != nil {
157
- logrus . Error ( err )
142
+ fmt . Printf ( "Error: %s" , err . Error () )
158
143
os .Exit (1 )
159
144
}
160
145
}
@@ -170,3 +155,22 @@ func createTable() *tablewriter.Table {
170
155
table .SetColWidth (100 )
171
156
return table
172
157
}
158
+
159
+ func getKubeClientBuilder (context string , namespace string , path string , inCluster bool ) kube.Kube {
160
+ return kube .New (& kube.Options {
161
+ ContextName : context ,
162
+ Namespace : namespace ,
163
+ PathToKubeConfig : path ,
164
+ InCluster : inCluster ,
165
+ })
166
+ }
167
+
168
+ func createLogger (command string , verbose bool ) logger.Logger {
169
+ logFile := "venonalog.json"
170
+ os .Remove (logFile )
171
+ return logger .New (& logger.Options {
172
+ Command : command ,
173
+ Verbose : verbose ,
174
+ LogToFile : logFile ,
175
+ })
176
+ }
0 commit comments