Skip to content

Commit 5f93f51

Browse files
Pass cluster id to helm values on agent installs (#105)
1 parent f54e020 commit 5f93f51

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

internal/resource/cluster.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (r *clusterResource) Create(ctx context.Context, req resource.CreateRequest
7676
}
7777

7878
if err = InstallOrUpgradeAgent(ctx, r.client, data.GetKubeconfig(), r.kubeClient, data.HelmRepoUrl.ValueString(),
79-
data.HelmValues.ValueStringPointer(), r.consoleUrl, lo.FromPtr(result.CreateCluster.DeployToken), &resp.Diagnostics); err != nil {
79+
data.HelmValues.ValueStringPointer(), r.consoleUrl, lo.FromPtr(result.CreateCluster.DeployToken), result.CreateCluster.ID, &resp.Diagnostics); err != nil {
8080
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to install operator, got error: %s", err))
8181
return
8282
}
@@ -135,7 +135,7 @@ func (r *clusterResource) Update(ctx context.Context, req resource.UpdateRequest
135135
return
136136
}
137137

138-
_, err := r.client.UpdateCluster(ctx, data.Id.ValueString(), data.UpdateAttributes(ctx, &resp.Diagnostics))
138+
result, err := r.client.UpdateCluster(ctx, data.Id.ValueString(), data.UpdateAttributes(ctx, &resp.Diagnostics))
139139
if err != nil {
140140
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to update cluster, got error: %s", err))
141141
return
@@ -151,7 +151,7 @@ func (r *clusterResource) Update(ctx context.Context, req resource.UpdateRequest
151151
}
152152

153153
if err = InstallOrUpgradeAgent(ctx, r.client, data.GetKubeconfig(), r.kubeClient, data.HelmRepoUrl.ValueString(),
154-
data.HelmValues.ValueStringPointer(), r.consoleUrl, lo.FromPtr(clusterWithToken.Cluster.DeployToken), &resp.Diagnostics); err != nil {
154+
data.HelmValues.ValueStringPointer(), r.consoleUrl, lo.FromPtr(clusterWithToken.Cluster.DeployToken), result.UpdateCluster.ID, &resp.Diagnostics); err != nil {
155155
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to install operator, got error: %s", err))
156156
return
157157
}

internal/resource/cluster_operator_handler.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
)
3333

3434
func InstallOrUpgradeAgent(ctx context.Context, client *client.Client, kubeconfig *common.Kubeconfig, kubeClient *common.KubeClient,
35-
repoUrl string, values *string, consoleUrl string, token string, d *diag.Diagnostics) error {
35+
repoUrl string, values *string, consoleUrl string, token string, clusterId string, d *diag.Diagnostics) error {
3636
workingDir, chartPath, err := fetchVendoredAgentChart(consoleUrl)
3737
if err != nil {
3838
d.AddWarning("Client Warning", fmt.Sprintf("Could not fetch vendored agent chart, using chart from the registry: %s", err))
@@ -53,7 +53,7 @@ func InstallOrUpgradeAgent(ctx context.Context, client *client.Client, kubeconfi
5353
}
5454
}
5555

56-
handler, err := NewOperatorHandler(ctx, client, kubeClient, repoUrl, chartPath, values, consoleUrl, token)
56+
handler, err := NewOperatorHandler(ctx, client, kubeClient, repoUrl, chartPath, values, consoleUrl, token, clusterId)
5757
if err != nil {
5858
return err
5959
}
@@ -82,7 +82,7 @@ func fetchVendoredAgentChart(consoleURL string) (string, string, error) {
8282
}
8383

8484
func NewOperatorHandler(ctx context.Context, client *client.Client, kubeClient *common.KubeClient,
85-
repoUrl, chartPath string, values *string, consoleUrl, token string) (*OperatorHandler, error) {
85+
repoUrl, chartPath string, values *string, consoleUrl, token string, clusterId string) (*OperatorHandler, error) {
8686
settings, err := client.GetDeploymentSettings(ctx)
8787
if err != nil {
8888
return nil, err
@@ -108,6 +108,7 @@ func NewOperatorHandler(ctx context.Context, client *client.Client, kubeClient *
108108
clientSet: clientSet,
109109
vendoredChartPath: chartPath,
110110
additionalValues: additionalValues,
111+
clusterId: clusterId,
111112
}
112113

113114
if err := handler.init(kubeClient, repoUrl); err != nil {
@@ -123,6 +124,7 @@ type OperatorHandler struct {
123124
deployToken string
124125
settings *gqlclient.DeploymentSettingsFragment
125126
clientSet *kubernetes.Clientset
127+
clusterId string
126128

127129
// vendoredChartPath contains a local path to vendored agent chart if it was downloadable, it is empty otherwise.
128130
vendoredChartPath string
@@ -264,5 +266,6 @@ func (oh *OperatorHandler) values() (map[string]any, error) {
264266
return algorithms.Merge(map[string]any{
265267
"secrets": map[string]string{"deployToken": oh.deployToken},
266268
"consoleUrl": console.NormalizeExtUrl(oh.consoleURL),
269+
"clusterId": oh.clusterId,
267270
}, oh.additionalValues, settingsValues), nil
268271
}

0 commit comments

Comments
 (0)