Skip to content

Commit 763b9b8

Browse files
Saas 8162 (#189)
Add support to inject resources via values files Co-authored-by: Roi Kramer <[email protected]>
1 parent 82c6a50 commit 763b9b8

31 files changed

+380
-190
lines changed

venona/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.27
1+
1.4.28

venonactl/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.27
1+
1.4.28

venonactl/cmd/attach.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ var attachRuntimeCmdOptions struct {
3939
kubePath string
4040
context string
4141
}
42-
restartAgent bool
43-
templateValues []string
44-
templateFileValues []string
45-
templateValueFiles []string
42+
restartAgent bool
43+
templateValues []string
44+
templateFileValues []string
45+
templateValueFiles []string
4646
}
4747

4848
var attachRuntimeCmd = &cobra.Command{
4949
Use: "attach",
5050
Short: "Attach Codefresh runtime to agent",
5151
Run: func(cmd *cobra.Command, args []string) {
52-
// get valuesMap from --values <values.yaml> --set-value k=v --set-file k=<context-of file>
52+
// get valuesMap from --values <values.yaml> --set-value k=v --set-file k=<context-of file>
5353
templateValuesMap, err := templateValuesToMap(
54-
attachRuntimeCmdOptions.templateValueFiles,
55-
attachRuntimeCmdOptions.templateValues,
54+
attachRuntimeCmdOptions.templateValueFiles,
55+
attachRuntimeCmdOptions.templateValues,
5656
attachRuntimeCmdOptions.templateFileValues)
5757
if err != nil {
5858
dieOnError(err)
@@ -120,7 +120,7 @@ var attachRuntimeCmd = &cobra.Command{
120120
builder.Add(plugins.RuntimeAttachType)
121121

122122
values := s.BuildValues()
123-
values = mergeMaps(values, templateValuesMap)
123+
values = mergeMaps(values, templateValuesMap)
124124
spn := createSpinner("Attaching runtime to agent (might take a few seconds)", "")
125125
spn.Start()
126126
for _, p := range builder.Get() {

venonactl/cmd/cmdutils.go

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

33
import (
4-
54
"fmt"
65
"io/ioutil"
76
"os"
@@ -25,9 +24,9 @@ import (
2524
k8sApi "k8s.io/api/core/v1"
2625
"k8s.io/client-go/tools/clientcmd"
2726

27+
"github.com/stretchr/objx"
2828
cliValues "helm.sh/helm/v3/pkg/cli/values"
2929
"helm.sh/helm/v3/pkg/getter"
30-
"github.com/stretchr/objx"
3130
)
3231

3332
var (
@@ -230,24 +229,24 @@ func extendStoreWithAgentAPI(logger logger.Logger, token string, agentID string)
230229
// Parsing helpers --set-value , --set-file
231230
// by https://github.com/helm/helm/blob/ec1d1a3d3eb672232f896f9d3b3d0797e4f519e3/pkg/cli/values/options.go#L41
232231

233-
// templateValuesToMap - processes cmd --values <values-file.yaml> --set-value k=v --set-file v=<context-of-file>
232+
// templateValuesToMap - processes cmd --values <values-file.yaml> --set-value k=v --set-file v=<context-of-file>
234233
// using helm libraries
235234
func templateValuesToMap(templateValueFiles, templateValues, templateFileValues []string) (map[string]interface{}, error) {
236235
valueOpts := &cliValues.Options{}
237236
if len(templateValueFiles) > 0 {
238-
for _, v := range(templateValueFiles) {
237+
for _, v := range templateValueFiles {
239238
valueOpts.ValueFiles = append(valueOpts.ValueFiles, v)
240239
}
241240
}
242-
241+
243242
if len(templateValues) > 0 {
244-
for _, v := range(templateValues) {
243+
for _, v := range templateValues {
245244
valueOpts.Values = append(valueOpts.Values, v)
246-
}
245+
}
247246
}
248-
247+
249248
if len(templateFileValues) > 0 {
250-
for _, v := range(templateFileValues) {
249+
for _, v := range templateFileValues {
251250
valueOpts.FileValues = append(valueOpts.FileValues, v)
252251
}
253252
}
@@ -275,24 +274,33 @@ func mergeMaps(a, b map[string]interface{}) map[string]interface{} {
275274
}
276275

277276
// mergeValueStr - for merging cli parameters with mapped parameters
278-
func mergeValueStr(valuesMap map[string]interface{}, key string, param *string) {
277+
func mergeValueStr(valuesMap map[string]interface{}, key string, param *string, defaultValue ...string) {
279278
mapX := objx.New(valuesMap)
280279
if param != nil && *param != "" {
281280
mapX.Set(key, *param)
282-
return
283-
}
284-
val := mapX.Get(key).String()
285-
*param = val
281+
return
282+
}
283+
val := mapX.Get(key).Str(defaultValue...)
284+
*param = val
286285
}
287286

288287
// mergeValueBool - for merging cli parameters with mapped parameters
289288
func mergeValueBool(valuesMap map[string]interface{}, key string, param *bool) {
290289
mapX := objx.New(valuesMap)
291-
if param != nil ||*param == true {
290+
if param != nil || *param == true {
292291
mapX.Set(key, *param)
293292
return
294293
}
295294
val := mapX.Get(key).Bool()
296295
*param = val
297296
}
298297

298+
func mergeValueMSI(valuesMap map[string]interface{}, key string, param *map[string]interface{}, defaultValue ...map[string]interface{}) {
299+
mapX := objx.New(valuesMap)
300+
if param != nil && len(*param) > 0 {
301+
mapX.Set(key, *param)
302+
return
303+
}
304+
val := mapX.Get(key).MSI(defaultValue...)
305+
*param = val
306+
}

venonactl/cmd/install-agent.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ var installAgentCmdOptions struct {
4949
templateValues []string
5050
templateFileValues []string
5151
templateValueFiles []string
52+
resources map[string]interface{}
5253
}
5354

5455
var installAgentCmd = &cobra.Command{
@@ -79,6 +80,8 @@ var installAgentCmd = &cobra.Command{
7980
mergeValueStr(templateValuesMap, "AgentId", &installAgentCmdOptions.agentID)
8081
mergeValueStr(templateValuesMap, "Image.Tag", &installAgentCmdOptions.venona.version)
8182

83+
mergeValueMSI(templateValuesMap, "Runner.resources", &installAgentCmdOptions.resources)
84+
8285
//mergeValueStrArray(&installAgentCmdOptions.envVars, "envVars", nil, "More env vars to be declared \"key=value\"")
8386

8487
mergeValueBool(templateValuesMap, "InCluster", &installAgentCmdOptions.kube.inCluster)
@@ -111,6 +114,7 @@ var installAgentCmd = &cobra.Command{
111114
}
112115

113116
fillKubernetesAPI(lgr, installAgentCmdOptions.kube.context, installAgentCmdOptions.kube.namespace, false)
117+
s.Runner.Resources = installAgentCmdOptions.resources
114118

115119
s.KubernetesAPI.Tolerations = tolerations
116120

venonactl/cmd/install-app-proxy.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,30 @@ var installAppProxyCmdOptions struct {
2828
namespace string
2929
context string
3030
}
31+
templateValues []string
32+
templateFileValues []string
33+
templateValueFiles []string
34+
resources map[string]interface{}
3135
}
3236

3337
var installAppProxyCmd = &cobra.Command{
3438
Use: "app-proxy",
3539
Short: "Install App proxy ",
3640
Run: func(cmd *cobra.Command, args []string) {
41+
42+
templateValuesMap, err := templateValuesToMap(
43+
installAppProxyCmdOptions.templateValueFiles,
44+
installAppProxyCmdOptions.templateValues,
45+
installAppProxyCmdOptions.templateFileValues)
46+
if err != nil {
47+
dieOnError(err)
48+
}
49+
50+
mergeValueStr(templateValuesMap, "Namespace", &installAppProxyCmdOptions.kube.namespace)
51+
mergeValueStr(templateValuesMap, "Context", &installAppProxyCmdOptions.kube.context)
52+
53+
mergeValueMSI(templateValuesMap, "AppProxy.resources", &installAppProxyCmdOptions.resources)
54+
3755
s := store.GetStore()
3856
lgr := createLogger("Install-agent", verbose, logFormatter)
3957
buildBasicStore(lgr)
@@ -44,21 +62,22 @@ var installAppProxyCmd = &cobra.Command{
4462
builderInstallOpt := &plugins.InstallOptions{
4563
CodefreshHost: cfAPIHost,
4664
}
47-
65+
s.AppProxy.Resources = installAppProxyCmdOptions.resources
4866
extendStoreWithKubeClient(lgr)
4967
fillCodefreshAPI(lgr)
5068
fillKubernetesAPI(lgr, installAppProxyCmdOptions.kube.context, installAppProxyCmdOptions.kube.namespace, false)
5169
s.AgentAPI = &store.AgentAPI{
5270
Token: "",
5371
Id: "",
5472
}
73+
5574
builderInstallOpt.ClusterName = s.KubernetesAPI.ContextName
5675
builderInstallOpt.KubeBuilder = getKubeClientBuilder(builderInstallOpt.ClusterName, s.KubernetesAPI.Namespace, s.KubernetesAPI.ConfigPath, s.KubernetesAPI.InCluster)
5776
builderInstallOpt.ClusterNamespace = s.KubernetesAPI.Namespace
5877
builder.Add(plugins.AppProxyPluginType)
5978

6079
values := s.BuildValues()
61-
var err error
80+
values = mergeMaps(values, templateValuesMap)
6281
spn := createSpinner("Installing app proxy (might take a few minutes)", "")
6382
spn.Start()
6483
defer spn.Stop()
@@ -79,4 +98,6 @@ func init() {
7998
installCommand.AddCommand(installAppProxyCmd)
8099
installAppProxyCmd.Flags().StringVar(&installAppProxyCmdOptions.kube.namespace, "kube-namespace", viper.GetString("kube-namespace"), "Name of the namespace on which venona should be installed [$KUBE_NAMESPACE]")
81100
installAppProxyCmd.Flags().StringVar(&installAppProxyCmdOptions.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]")
101+
installAppProxyCmd.Flags().StringArrayVarP(&installAppProxyCmdOptions.templateValueFiles, "values", "f", []string{}, "specify values in a YAML file")
102+
82103
}

venonactl/cmd/install-monitor.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/codefresh-io/venona/venonactl/pkg/store"
2424
"github.com/spf13/cobra"
2525
"github.com/spf13/viper"
26-
2726
)
2827

2928
var installMonitorAgentCmdOptions struct {
@@ -32,25 +31,26 @@ var installMonitorAgentCmdOptions struct {
3231
context string
3332
nodeSelector string
3433
}
35-
clusterId string
36-
helm3 bool
37-
codefreshToken string
38-
codefreshHost string
39-
dockerRegistry string
40-
templateValues []string
41-
templateFileValues []string
42-
templateValueFiles []string
34+
clusterId string
35+
helm3 bool
36+
codefreshToken string
37+
codefreshHost string
38+
dockerRegistry string
39+
templateValues []string
40+
templateFileValues []string
41+
templateValueFiles []string
42+
resources map[string]interface{}
4343
}
4444

4545
// installK8sAgentCmd represents the install command
4646
var installMonitorAgentCmd = &cobra.Command{
4747
Use: "monitor",
4848
Short: "Install Codefresh's monitor agent on cluster",
4949
Run: func(cmd *cobra.Command, args []string) {
50-
// get valuesMap from --values <values.yaml> --set-value k=v --set-file k=<context-of file>
50+
// get valuesMap from --values <values.yaml> --set-value k=v --set-file k=<context-of file>
5151
templateValuesMap, err := templateValuesToMap(
52-
installMonitorAgentCmdOptions.templateValueFiles,
53-
installMonitorAgentCmdOptions.templateValues,
52+
installMonitorAgentCmdOptions.templateValueFiles,
53+
installMonitorAgentCmdOptions.templateValues,
5454
installMonitorAgentCmdOptions.templateFileValues)
5555
if err != nil {
5656
dieOnError(err)
@@ -64,6 +64,8 @@ var installMonitorAgentCmd = &cobra.Command{
6464
mergeValueStr(templateValuesMap, "Namespace", &installMonitorAgentCmdOptions.kube.namespace)
6565
mergeValueStr(templateValuesMap, "Context", &installMonitorAgentCmdOptions.kube.context)
6666

67+
mergeValueMSI(templateValuesMap, "Monitor.resources", &installMonitorAgentCmdOptions.resources)
68+
6769
mergeValueStr(templateValuesMap, "DockerRegistry", &installMonitorAgentCmdOptions.dockerRegistry)
6870
mergeValueStr(templateValuesMap, "ClusterId", &installMonitorAgentCmdOptions.clusterId)
6971
mergeValueBool(templateValuesMap, "helm3", &installMonitorAgentCmdOptions.helm3)
@@ -74,6 +76,7 @@ var installMonitorAgentCmd = &cobra.Command{
7476
buildBasicStore(lgr)
7577
extendStoreWithKubeClient(lgr)
7678
fillKubernetesAPI(lgr, installMonitorAgentCmdOptions.kube.context, installMonitorAgentCmdOptions.kube.namespace, false)
79+
s.Monitor.Resources = installMonitorAgentCmdOptions.resources
7780

7881
builder := plugins.NewBuilder(lgr)
7982
builder.Add(plugins.MonitorAgentPluginType)

venonactl/cmd/install-runtime.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"github.com/codefresh-io/venona/venonactl/pkg/store"
2424
"github.com/spf13/cobra"
2525
"github.com/spf13/viper"
26-
2726
)
2827

2928
var installRuntimeCmdOptions struct {
@@ -44,17 +43,19 @@ var installRuntimeCmdOptions struct {
4443
templateValues []string
4544
templateFileValues []string
4645
templateValueFiles []string
46+
volumeProvisioner map[string]interface{}
47+
localVolumeMonitor map[string]interface{}
4748
}
4849

4950
var installRuntimeCmd = &cobra.Command{
5051
Use: "runtime",
5152
Short: "Install Codefresh's runtime",
5253
Run: func(cmd *cobra.Command, args []string) {
5354

54-
// get valuesMap from --values <values.yaml> --set-value k=v --set-file k=<context-of file>
55+
// get valuesMap from --values <values.yaml> --set-value k=v --set-file k=<context-of file>
5556
templateValuesMap, err := templateValuesToMap(
56-
installRuntimeCmdOptions.templateValueFiles,
57-
installRuntimeCmdOptions.templateValues,
57+
installRuntimeCmdOptions.templateValueFiles,
58+
installRuntimeCmdOptions.templateValues,
5859
installRuntimeCmdOptions.templateFileValues)
5960
if err != nil {
6061
dieOnError(err)
@@ -63,7 +64,7 @@ var installRuntimeCmd = &cobra.Command{
6364
mergeValueStr(templateValuesMap, "ConfigPath", &kubeConfigPath)
6465
mergeValueStr(templateValuesMap, "CodefreshHost", &cfAPIHost)
6566
mergeValueStr(templateValuesMap, "Token", &cfAPIToken)
66-
mergeValueStr(templateValuesMap, "Token", &installRuntimeCmdOptions.codefreshToken)
67+
mergeValueStr(templateValuesMap, "Token", &installRuntimeCmdOptions.codefreshToken)
6768

6869
mergeValueStr(templateValuesMap, "Namespace", &installRuntimeCmdOptions.kube.namespace)
6970
mergeValueStr(templateValuesMap, "Context", &installRuntimeCmdOptions.kube.context)
@@ -73,12 +74,24 @@ var installRuntimeCmd = &cobra.Command{
7374
//mergeValueStrArray(&installAgentCmdOptions.envVars, "envVars", nil, "More env vars to be declared \"key=value\"")
7475
mergeValueStr(templateValuesMap, "DockerRegistry", &installRuntimeCmdOptions.dockerRegistry)
7576
mergeValueStr(templateValuesMap, "StorageClass", &installRuntimeCmdOptions.storageClass)
76-
77+
78+
defaultVolumeProvResources := map[string]interface{}{
79+
"limits": map[string]string{
80+
"cpu": "1000m",
81+
"memory": "6000Mi",
82+
},
83+
"requests": map[string]string{
84+
"cpu": "200m",
85+
"memory": "200Mi",
86+
},
87+
}
88+
mergeValueMSI(templateValuesMap, "Storage.VolumeProvisioner.resources", &installRuntimeCmdOptions.volumeProvisioner, defaultVolumeProvResources)
89+
mergeValueMSI(templateValuesMap, "Storage.LocalVolumeMonitor.resources", &installRuntimeCmdOptions.localVolumeMonitor)
90+
7791
mergeValueBool(templateValuesMap, "InCluster", &installRuntimeCmdOptions.kube.inCluster)
7892
mergeValueBool(templateValuesMap, "insecure", &installRuntimeCmdOptions.insecure)
7993
mergeValueBool(templateValuesMap, "kubernetesRunnerType", &installRuntimeCmdOptions.kubernetesRunnerType)
8094

81-
8295
s := store.GetStore()
8396
lgr := createLogger("Install-runtime", verbose, logFormatter)
8497
buildBasicStore(lgr)
@@ -140,6 +153,8 @@ var installRuntimeCmd = &cobra.Command{
140153
}
141154

142155
fillKubernetesAPI(lgr, installRuntimeCmdOptions.kube.context, installRuntimeCmdOptions.kube.namespace, installRuntimeCmdOptions.kube.inCluster)
156+
s.VolumeProvisioner.Resources = installRuntimeCmdOptions.volumeProvisioner
157+
s.LocalVolumeMonitor.Resources = installRuntimeCmdOptions.localVolumeMonitor
143158

144159
if installRuntimeCmdOptions.dryRun {
145160
s.DryRun = installRuntimeCmdOptions.dryRun

venonactl/cmd/install.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ limitations under the License.
1616
*/
1717

1818
import (
19-
2019
"github.com/spf13/cobra"
2120
)
2221

venonactl/cmd/migrate.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
*/
1818

1919
import (
20-
2120
"github.com/codefresh-io/venona/venonactl/pkg/plugins"
2221
"github.com/codefresh-io/venona/venonactl/pkg/store"
2322
"github.com/spf13/cobra"
@@ -26,7 +25,7 @@ import (
2625

2726
var migrateCmdOpt struct {
2827
kube struct {
29-
context string
28+
context string
3029
namespace string
3130
}
3231
}
@@ -52,10 +51,10 @@ var migrateCmd = &cobra.Command{
5251
spn.Start()
5352
defer spn.Stop()
5453
for _, p := range builder.Get() {
55-
err := p.Migrate( &plugins.MigrateOptions{
54+
err := p.Migrate(&plugins.MigrateOptions{
5655
ClusterNamespace: migrateCmdOpt.kube.namespace,
57-
ClusterName: migrateCmdOpt.kube.context,
58-
KubeBuilder: getKubeClientBuilder(migrateCmdOpt.kube.context, migrateCmdOpt.kube.namespace, s.KubernetesAPI.ConfigPath, s.KubernetesAPI.InCluster),
56+
ClusterName: migrateCmdOpt.kube.context,
57+
KubeBuilder: getKubeClientBuilder(migrateCmdOpt.kube.context, migrateCmdOpt.kube.namespace, s.KubernetesAPI.ConfigPath, s.KubernetesAPI.InCluster),
5958
}, values)
6059
if err != nil {
6160
dieOnError(err)

0 commit comments

Comments
 (0)