Modify rad install to create default resource group and environment#11870
Modify rad install to create default resource group and environment#11870zachcasper wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates rad install kubernetes so that, after a successful Helm install, it also ensures a usable default setup by creating a default resource group and a default environment targeting the default Kubernetes namespace—bringing the command in line with rad init.
Changes:
- Add a post-install step to create the
defaultresource group anddefaultenvironment after Helm installation completes. - Add kube context resolution logic that falls back to the current kubeconfig context when
--kubecontextisn’t provided. - Update/install unit tests to cover the new post-install behavior and kubeconfig edge cases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/cli/cmd/install/kubernetes/kubernetes.go | Adds post-install default resource group/environment creation and kube context resolution helpers. |
| pkg/cli/cmd/install/kubernetes/kubernetes_test.go | Updates existing tests for new expectations and adds tests for kubecontext fallback and missing current context. |
Comments suppressed due to low confidence (1)
pkg/cli/cmd/install/kubernetes/kubernetes.go:235
CreateOrUpdateResourceGroup/CreateOrUpdateEnvironmentare full upserts (PUT) and will update an existingdefaultgroup/environment to match the payload here. That contradicts the comment about leaving existing resources unchanged and can reset user edits during--reinstall(e.g., environment compute kind/namespace). To preserve user changes, check for existence first (GET; treat 404 as "missing"), and only create when absent (or explicitly skip update when an existing resource differs).
// createDefaultGroupAndEnvironment ensures that a resource group named "default" and an environment named
// "default" exist on the cluster Radius was just installed on. Existing resources with the same names are
// left unchanged (CreateOrUpdate semantics), so re-running install is safe.
func (r *Runner) createDefaultGroupAndEnvironment(ctx context.Context) error {
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #11870 +/- ##
==========================================
- Coverage 51.72% 51.71% -0.02%
==========================================
Files 726 727 +1
Lines 45608 45650 +42
==========================================
+ Hits 23591 23608 +17
- Misses 19793 19813 +20
- Partials 2224 2229 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Zach Casper <zachcasper@microsoft.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Zach Casper <zachcasper@microsoft.com>
Signed-off-by: Zach Casper <zachcasper@microsoft.com>
ac946ca to
1237de9
Compare
Radius functional test overviewClick here to see the test run details
Test Status⌛ Building Radius and pushing container images for functional tests... |
willdavsmith
left a comment
There was a problem hiding this comment.
looks good, left a couple of comments
| // resolveKubeContext returns the kube context the install targeted. If --kubecontext was passed, that value | ||
| // is used. Otherwise the active kube context from the user's kubeconfig is used (matching what the Helm | ||
| // install actually targeted). | ||
| func (r *Runner) resolveKubeContext() (string, error) { |
There was a problem hiding this comment.
why do we need this function? I assume that we have to do this type of operation elsewhere in the CLI. How do we handle it there?
| t.Helper() | ||
| mgmtMock := clients.NewMockApplicationsManagementClient(ctrl) | ||
| mgmtMock.EXPECT(). | ||
| CreateOrUpdateResourceGroup(gomock.Any(), "local", "default", gomock.Any()). |
There was a problem hiding this comment.
since these are mocks could we add a couple of tests to simulate failed rg and env creation?
Description
rad install kubernetespreviously only installed the Radius Helm chart, leaving the cluster without a usable resource group or environment. Users then had to run additional commands (or userad init) before they could deploy anything. This PR bringsrad install kubernetesin line withrad initby automatically creating thedefaultresource group and adefaultenvironment (in thedefaultKubernetes namespace) immediately after a successful Helm install.Behavior:
Helm.InstallRadiussucceeds, the runner builds an in-process workspace targeting the just-installed control plane and callsCreateOrUpdateResourceGroup(ctx, "local", "default", …)andCreateOrUpdateEnvironment(ctx, "default", …)withKubernetesCompute{Namespace: "default"}.CreateOrUpdatesemantics make the calls idempotent — re-running with--reinstallwill not corrupt user-edited groups/environments.--reinstall) is unchanged: nothing is touched.--kubecontextif set, otherwise the active context from kubeconfig. If kubeconfig has no active context, a clear error tells the user to pass--kubecontext.rad group create default/rad env create default) so they don't have to reinstall.~/.rad/config.yaml; the workspace used here is in-process only.Files changed:
pkg/cli/cmd/install/kubernetes/kubernetes.go: addsConnectionFactory+KubernetesInterfacetoRunner, the post-installcreateDefaultGroupAndEnvironmentstep,resolveKubeContexthelper, default constants, updatedLongdescription.pkg/cli/cmd/install/kubernetes/kubernetes_test.go: updates all successful-install tests with the new mock expectations, adds a test for the kubeconfig-fallback path and a test for the empty-current-context failure path. Mock expectations assertLocation == LocationGlobalandKubernetesCompute.Namespace == "default"on the env payload.Type of change
Fixes: #11869
Contributor checklist
Please verify that the PR meets the following requirements, where applicable:
eng/design-notes/in this repository, if new APIs are being introduced.rad install kubernetesuser-facing behavior changes; docs should call out the new default group/env and the new failure modes.