Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support rad install kubernetes --set values #5243

Merged
merged 20 commits into from
Mar 20, 2023
Merged

support rad install kubernetes --set values #5243

merged 20 commits into from
Mar 20, 2023

Conversation

nithyatsu
Copy link
Contributor

@nithyatsu nithyatsu commented Mar 7, 2023

Description

Introduce rad install kubernetes --set
which can set single or multiple comma separated values for helm chart.

ex:
rad install kubernetes --set global.ucp.image=radius.azurecr.io/ucpd,global.ucp.tag=latest

rad install kubernetes --set global.tracerProvider.zipkin.url=http://jaeger-collector.radius-monitoring.svc.cluster.local:9411/api/v2/spans

Issue reference

Partially Fixes: radius-project/core-team#1117 based on discussion here : https://github.com/project-radius/radius/issues/5173#issuecomment-1452655212

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Adds necessary unit tests for change
  • Adds necessary E2E tests for change
  • Unit tests passing
  • Extended the documentation / Created issue for it

@nithyatsu nithyatsu changed the title initial commit support rad install kubernetes --set values Mar 7, 2023
logging:
log: "info"
json: true
tracerProvider:
serviceName: "applications.core"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be link?

@@ -399,6 +399,6 @@ func createEnvironmentResource(ctx context.Context, kubeCtxName, resourceGroupNa
}

func isEmpty(chartArgs *setup.ChartArgs) bool {
var emptyChartArgs setup.ChartArgs
return (chartArgs == nil || *chartArgs == emptyChartArgs)
//var emptyChartArgs setup.ChartArgs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I introduced a slice of string it does not allow it any more. I might have to add some more code to test fr isEmpty once I get the main functionality working.

@@ -40,7 +40,8 @@ logging:
json: true
tracerProvider:
serviceName: "applications.link"

zipkin:
url: "http://jaeger-collector.radius-monitoring.svc.cluster.local:9411/api/v2/spans"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commented out code can be deleted

Comment on lines 47 to 48
# url: "http://jaeger-collector.radius-monitoring.svc.cluster.local:9411/api/v2/spans" No newline at end of file
#url: "http://jaeger-collector.radius-monitoring.svc.cluster.local:9411/api/v2/spans"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here (commented out code can be deleted)

@@ -57,7 +57,7 @@ spec:
- containerPort: {{ .Values.global.prometheus.port }}
name: metrics
protocol: TCP
{{ end }}
{{ end }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might create an issue while deploying the chart (extra spaces need to be deleted)

@@ -64,7 +64,9 @@ logging:
json: true

tracerProvider:
serviceName: "ucp"
serviceName: "applications.core"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be ucp?

serviceName: "ucp"
serviceName: "applications.core"
zipkin:
url: "http://jaeger-collector.radius-monitoring.svc.cluster.local:9411/api/v2/spans"

# TODO: Enable trace provider in 0.19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove

@@ -105,7 +105,9 @@ func PopulateDefaultClusterOptions(cliOptions CLIClusterOptions) ClusterOptions
if cliOptions.Radius.AWSProvider != nil {
options.Radius.AWSProvider = cliOptions.Radius.AWSProvider
}

if len(cliOptions.Radius.Values) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite sure why we need the values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are trying to implement https://github.com/project-radius/radius/issues/5173#issuecomment-1452655212
it would be somewhat like a wrapper around helm install ( or upgrade)'s set command

@@ -194,6 +207,35 @@ func GetAzProvider(options RadiusOptions, kubeContext string) (*azure.Provider,

}

func GetHelmValues(kubeContext string) (map[string]interface{}, error) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove extra line

@@ -24,8 +24,13 @@ type ChartArgs struct {
// for display purposes. This is useful when the the actual public IP address of a cluster's ingress
// is not a routable IP. This comes up all of the time for a local cluster.
PublicEndpointOverride string
Values []string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

Copy link
Contributor Author

@nithyatsu nithyatsu Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, thats the support for rad install kubernetes --set command. (https://github.com/project-radius/radius/issues/5173#issuecomment-1452655212

@github-actions
Copy link

github-actions bot commented Mar 8, 2023

60.0

For the detailed report, please go to Checks tab, click Build and Test, and then download unit_test_coverage artifact at the bottom of build page.

  • Your PR branch coverage: 60.0 %
  • main branch coverage: 60.3 %

The coverage result does not include the functional test coverage.

@github-actions
Copy link

github-actions bot commented Mar 8, 2023

60.1

For the detailed report, please go to Checks tab, click Build and Test, and then download unit_test_coverage artifact at the bottom of build page.

  • Your PR branch coverage: 60.1 %
  • main branch coverage: 60.3 %

The coverage result does not include the functional test coverage.

@nithyatsu nithyatsu marked this pull request as ready for review March 8, 2023 21:26
@nithyatsu nithyatsu requested a review from a team as a code owner March 8, 2023 21:26
@nithyatsu nithyatsu requested a review from youngbupark March 8, 2023 21:27
@github-actions
Copy link

github-actions bot commented Mar 8, 2023

60.2

For the detailed report, please go to Checks tab, click Build and Test, and then download unit_test_coverage artifact at the bottom of build page.

  • Your PR branch coverage: 60.2 %
  • main branch coverage: 60.3 %

The coverage result does not include the functional test coverage.

Copy link

@youngbupark youngbupark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the existing pkgs from helm repo as possible instead of creating new wheel.

@@ -24,8 +24,13 @@ type ChartArgs struct {
// for display purposes. This is useful when the the actual public IP address of a cluster's ingress
// is not a routable IP. This comes up all of the time for a local cluster.
PublicEndpointOverride string
Values []string

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comments here.

Suggested change
Values []string
Values []string

@@ -213,6 +221,38 @@ func runRadiusHelmUpgrade(helmConf *helm.Configuration, releaseName string, helm
return runUpgrade(installClient, releaseName, helmChart)
}

func addChartValues(helmChart *chart.Chart, values []string) error {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need to implement key and value parser.
Please refer the following helm chart pkgs:

  1. https://github.com/helm/helm/blob/main/pkg/strvals/parser.go
  2. https://github.com/helm/helm/blob/main/pkg/cli/values/options.go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reimplemented.

@github-actions
Copy link

github-actions bot commented Mar 8, 2023

60.1

For the detailed report, please go to Checks tab, click Build and Test, and then download unit_test_coverage artifact at the bottom of build page.

  • Your PR branch coverage: 60.1 %
  • main branch coverage: 60.3 %

The coverage result does not include the functional test coverage.

@@ -400,5 +401,6 @@ func createEnvironmentResource(ctx context.Context, kubeCtxName, resourceGroupNa

func isEmpty(chartArgs *setup.ChartArgs) bool {
var emptyChartArgs setup.ChartArgs
return (chartArgs == nil || *chartArgs == emptyChartArgs)
emptyChartArgs.Values = []string{}
return (chartArgs == nil || reflect.DeepEqual(*chartArgs, emptyChartArgs))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it sufficient to check len?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chartArgs now has a slice Values, therefore deepcopy was needed..

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my comment. I recommend to use string for values arg because helm's parser parse strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reimplemented using string. Please see if that looks better.

@@ -37,6 +42,7 @@ func RegisterPersistentChartArgs(cmd *cobra.Command) {
cmd.PersistentFlags().String("ucp-image", "", "Specify the UCP image to use")
cmd.PersistentFlags().String("ucp-tag", "", "Specify the UCP tag to use")
cmd.PersistentFlags().String("public-endpoint-override", "", "Specify the public IP address or hostname of the Kubernetes cluster. It must be in the format: <hostname>[:<port>]. Ex: 'localhost:9000'")
cmd.PersistentFlags().StringArrayVar(&values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name "values" isn't very intuitive. Have you checked this with PM?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AaronCrawfis approved rad install kuberenetes --set.

I got the idea of values from dapr and it seemed to make sense since we are somewhat implementing a wrapper around helm's install/ upgrade, which will overwrite the values.yaml values (https://github.com/project-radius/radius/issues/5173#issuecomment-1452655212 ). Should I rename it to something else?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest run it by him once....whether we want to call it helmValues or something

@@ -24,8 +24,13 @@ type ChartArgs struct {
// for display purposes. This is useful when the the actual public IP address of a cluster's ingress
// is not a routable IP. This comes up all of the time for a local cluster.
PublicEndpointOverride string
Values []string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some comments here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@github-actions
Copy link

60.3

For the detailed report, please go to Checks tab, click Build and Test, and then download unit_test_coverage artifact at the bottom of build page.

  • Your PR branch coverage: 60.3 %
  • main branch coverage: 60.3 %

The coverage result does not include the functional test coverage.

@@ -37,6 +44,7 @@ func RegisterPersistentChartArgs(cmd *cobra.Command) {
cmd.PersistentFlags().String("ucp-image", "", "Specify the UCP image to use")
cmd.PersistentFlags().String("ucp-tag", "", "Specify the UCP tag to use")
cmd.PersistentFlags().String("public-endpoint-override", "", "Specify the public IP address or hostname of the Kubernetes cluster. It must be in the format: <hostname>[:<port>]. Ex: 'localhost:9000'")
cmd.PersistentFlags().StringArrayVar(&values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use String() instead of StringArrayVar(). helm's strvals.ParseInto(val, helmChart.Values) has its own parser to parse comma and KV. So we do not need to get this as value array. Then you do not need addChartValues because you can just call strvals.ParseInto directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

@github-actions
Copy link

60.4

For the detailed report, please go to Checks tab, click Build and Test, and then download unit_test_coverage artifact at the bottom of build page.

  • Your PR branch coverage: 60.4 %
  • main branch coverage: 60.3 %

The coverage result does not include the functional test coverage.

@nithyatsu nithyatsu requested a review from youngbupark March 13, 2023 22:25
err = addRadiusValues(helmChart, &options)
if err != nil {
return false, fmt.Errorf("failed to add radius values, err: %w, helm output: %s", err, helmOutput.String())
}

if options.Values != "" {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think empty string should be handled by ParseInto. so we do not need this if else.

err = addRadiusValues(helmChart, &options)
if err != nil {
return false, fmt.Errorf("failed to add radius values, err: %w, helm output: %s", err, helmOutput.String())
}

if options.Values != "" {
err := strvals.ParseInto(options.Values, helmChart.Values)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it overriding the values from L78 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would overwrite if the keys match, for example if someone specified a set with globar.rp.container. I thought eventually when we refactor helm in next sprint, we would remove addRadiusValues and just document --set usage to set different values.
So I had added a TODO comment at L77. Should I add checks to make sure we arent using set for thos eparameters alone?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#5284 created to use this function for functionalities of --tag, --image etc

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. then I would move this strvals.ParseInto to the end of the existing addRadiusValues function and have the unit-test for addRadiusValues.

@nithyatsu nithyatsu requested a review from youngbupark March 14, 2023 18:39
@github-actions
Copy link

60.3

For the detailed report, please go to Checks tab, click Build and Test, and then download unit_test_coverage artifact at the bottom of build page.

  • Your PR branch coverage: 60.3 %
  • main branch coverage: 60.3 %

The coverage result does not include the functional test coverage.

@github-actions
Copy link

60.6

For the detailed report, please go to Checks tab, click Build and Test, and then download unit_test_coverage artifact at the bottom of build page.

  • Your PR branch coverage: 60.6 %
  • main branch coverage: 60.3 %

The coverage result does not include the functional test coverage.

@youngbupark
Copy link

60.6

For the detailed report, please go to Checks tab, click Build and Test, and then download unit_test_coverage artifact at the bottom of build page.

  • Your PR branch coverage: 60.6 %
  • main branch coverage: 60.3 %

The coverage result does not include the functional test coverage.

@nithyatsu Thanks! You increased 0.3 % of our test coverage!

Copy link

@youngbupark youngbupark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It increased 0.3% coverage!!!

Thanks for this! I left two comments. Please resolve them before merge :)

@@ -284,6 +287,13 @@ func addRadiusValues(helmChart *chart.Chart, options *RadiusOptions) error {
de["tag"] = options.DETag
}

if options.Values != "" {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ParseInfo takes care of empty string. So we do not need this check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed it


func Test_AddRadiusValues(t *testing.T) {
var helmChart chart.Chart
helmChart.Values = map[string]interface{}{}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
helmChart.Values = map[string]interface{}{}
helmChart.Values = map[string]any{}

@github-actions
Copy link

60.5

For the detailed report, please go to Checks tab, click Build and Test, and then download unit_test_coverage artifact at the bottom of build page.

  • Your PR branch coverage: 60.5 %
  • main branch coverage: 60.3 %
  • diff coverage: .2 %

The coverage result does not include the functional test coverage.

@rynowak
Copy link
Contributor

rynowak commented Mar 20, 2023

😍 really glad to see this getting worked on

@rynowak
Copy link
Contributor

rynowak commented Mar 20, 2023

@nithyatsu

  • Can you please link the issue?
  • If there was a design review, can you make sure the relevant details got copied into the issue?
  • If there wasn't a design review, please get one queued up. We should be doing design reviews for CLI UX changes.

@rynowak
Copy link
Contributor

rynowak commented Mar 20, 2023

Introduce rad install kubernetes --args which can set single or multiple comma separated values for helm chart.

I'm confused about something.... the title says introduce --set and then the commit message says --args. But I don't see either of these things in the PR.

@nithyatsu
Copy link
Contributor Author

Introduce rad install kubernetes --args which can set single or multiple comma separated values for helm chart.

I'm confused about something.... the title says introduce --set and then the commit message says --args. But I don't see either of these things in the PR.

Missed updating description... Should be OK now. Also added the github user stopry that gets partially fixed by this command.

@rynowak
Copy link
Contributor

rynowak commented Mar 20, 2023

Thanks 👍 - we need to get in the habit of including this info for when we're open source.

@@ -37,6 +40,7 @@ func RegisterPersistentChartArgs(cmd *cobra.Command) {
cmd.PersistentFlags().String("ucp-image", "", "Specify the UCP image to use")
cmd.PersistentFlags().String("ucp-tag", "", "Specify the UCP tag to use")
cmd.PersistentFlags().String("public-endpoint-override", "", "Specify the public IP address or hostname of the Kubernetes cluster. It must be in the format: <hostname>[:<port>]. Ex: 'localhost:9000'")
cmd.PersistentFlags().String("set", "", "Set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an example of this to rad install kubernetes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rynowak
Copy link
Contributor

rynowak commented Mar 20, 2023

You're also doing #3937

@github-actions
Copy link

60.5

For the detailed report, please go to Checks tab, click Build and Test, and then download unit_test_coverage artifact at the bottom of build page.

  • Your PR branch coverage: 60.5 %
  • main branch coverage: 60.3 %
  • diff coverage: .2 %

The coverage result does not include the functional test coverage.

@nithyatsu
Copy link
Contributor Author

You're also doing #3937

For tracer feature mvp, I am templatizing config map and exposing tracer url as a templatized value. This is what I am doing as part of https://dev.azure.com/azure-octo/Incubations/_workitems/edit/6520 . Perhaps I should have a discussion around what else should be available as template?

@nithyatsu nithyatsu merged commit 5918d73 into main Mar 20, 2023
@nithyatsu nithyatsu deleted the nithya/chartargs branch March 20, 2023 20:17
@rynowak
Copy link
Contributor

rynowak commented Mar 20, 2023

You're also doing #3937

For tracer feature mvp, I am templatizing config map and exposing tracer url as a templatized value. This is what I am doing as part of https://dev.azure.com/azure-octo/Incubations/_workitems/edit/6520 . Perhaps I should have a discussion around what else should be available as template?

But you did implement #3937 - this is a new CLI feature to pass values to the helm chart during installation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants