Skip to content

Commit fbbf3e6

Browse files
committed
install operator via helm on a byok cluster
1 parent 80873ca commit fbbf3e6

File tree

12 files changed

+220
-83
lines changed

12 files changed

+220
-83
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ require (
1313
github.com/pluralsh/plural-cli v0.8.1-0.20231114161007-183eafb99b03
1414
github.com/pluralsh/polly v0.1.4
1515
github.com/samber/lo v1.38.1
16+
github.com/sirupsen/logrus v1.9.3
17+
helm.sh/helm/v3 v3.11.2
1618
k8s.io/apimachinery v0.26.4
1719
k8s.io/client-go v0.26.4
1820
)
@@ -254,7 +256,6 @@ require (
254256
github.com/sergi/go-diff v1.3.1 // indirect
255257
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c // indirect
256258
github.com/shopspring/decimal v1.3.1 // indirect
257-
github.com/sirupsen/logrus v1.9.3 // indirect
258259
github.com/sivchari/containedctx v1.0.3 // indirect
259260
github.com/sivchari/nosnakecase v1.7.0 // indirect
260261
github.com/sivchari/tenv v1.7.1 // indirect
@@ -324,7 +325,6 @@ require (
324325
gopkg.in/warnings.v0 v0.1.2 // indirect
325326
gopkg.in/yaml.v2 v2.4.0 // indirect
326327
gopkg.in/yaml.v3 v3.0.1 // indirect
327-
helm.sh/helm/v3 v3.11.2 // indirect
328328
honnef.co/go/tools v0.4.6 // indirect
329329
k8s.io/api v0.26.4 // indirect
330330
k8s.io/apiextensions-apiserver v0.26.1 // indirect

internal/datasource/cluster.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (d *clusterDataSource) Configure(_ context.Context, req datasource.Configur
6969
return
7070
}
7171

72-
c, ok := req.ProviderData.(*client.Client)
72+
data, ok := req.ProviderData.(*model.ProviderData)
7373
if !ok {
7474
resp.Diagnostics.AddError(
7575
"Unexpected Cluster Resource Configure Type",
@@ -78,7 +78,7 @@ func (d *clusterDataSource) Configure(_ context.Context, req datasource.Configur
7878
return
7979
}
8080

81-
d.client = c
81+
d.client = data.Client
8282
}
8383

8484
func (d *clusterDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {

internal/datasource/gitrepository.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/samber/lo"
1515

1616
"terraform-provider-plural/internal/client"
17+
"terraform-provider-plural/internal/model"
1718
)
1819

1920
func NewGitRepositoryDataSource() datasource.DataSource {
@@ -90,8 +91,7 @@ func (r *GitRepositoryDataSource) Configure(_ context.Context, req datasource.Co
9091
return
9192
}
9293

93-
c, ok := req.ProviderData.(*client.Client)
94-
94+
data, ok := req.ProviderData.(*model.ProviderData)
9595
if !ok {
9696
resp.Diagnostics.AddError(
9797
"Unexpected GitRepository Resource Configure Type",
@@ -101,7 +101,7 @@ func (r *GitRepositoryDataSource) Configure(_ context.Context, req datasource.Co
101101
return
102102
}
103103

104-
r.client = c
104+
r.client = data.Client
105105
}
106106

107107
func (r *GitRepositoryDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {

internal/model/cluster.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package model
2+
3+
import "github.com/hashicorp/terraform-plugin-framework/types"
4+
5+
// Cluster describes the cluster resource and data source model.
6+
type Cluster struct {
7+
Id types.String `tfsdk:"id"`
8+
InseredAt types.String `tfsdk:"inserted_at"`
9+
Name types.String `tfsdk:"name"`
10+
Handle types.String `tfsdk:"handle"`
11+
Cloud types.String `tfsdk:"cloud"`
12+
Protect types.Bool `tfsdk:"protect"`
13+
Tags types.Map `tfsdk:"tags"`
14+
Kubeconfig Kubeconfig `tfsdk:"kubeconfig"`
15+
}
16+
17+
type Kubeconfig struct {
18+
Host types.String `tfsdk:"host"`
19+
Username types.String `tfsdk:"username"`
20+
Password types.String `tfsdk:"password"`
21+
Insecure types.Bool `tfsdk:"insecure"`
22+
TlsServerName types.String `tfsdk:"tls_server_name"`
23+
ClientCertificate types.String `tfsdk:"client_certificate"`
24+
ClientKey types.String `tfsdk:"client_key"`
25+
ClusterCACertificate types.String `tfsdk:"cluster_ca_certificate"`
26+
ConfigPath types.String `tfsdk:"config_path"`
27+
ConfigContext types.String `tfsdk:"config_context"`
28+
ConfigContextAuthInfo types.String `tfsdk:"config_context_auth_info"`
29+
ConfigContextCluster types.String `tfsdk:"config_context_cluster"`
30+
Token types.String `tfsdk:"token"`
31+
ProxyURL types.String `tfsdk:"proxy_url"`
32+
Exec *KubeconfigExec `tfsdk:"exec"`
33+
}
34+
35+
type KubeconfigExec struct {
36+
Command types.String `tfsdk:"command"`
37+
Args types.String `tfsdk:"args"`
38+
Env types.String `tfsdk:"env"`
39+
APIVersion types.String `tfsdk:"api_version"`
40+
}

internal/model/model.go

Lines changed: 0 additions & 39 deletions
This file was deleted.

internal/model/provider.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package model
2+
3+
import (
4+
internalclient "terraform-provider-plural/internal/client"
5+
)
6+
7+
type ProviderData struct {
8+
Client *internalclient.Client
9+
ConsoleUrl string
10+
}
11+
12+
func NewProviderData(client *internalclient.Client, consoleUrl string) *ProviderData {
13+
return &ProviderData{
14+
Client: client,
15+
ConsoleUrl: consoleUrl,
16+
}
17+
}

internal/provider/provider.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
internalclient "terraform-provider-plural/internal/client"
1111
ds "terraform-provider-plural/internal/datasource"
12+
"terraform-provider-plural/internal/model"
1213
r "terraform-provider-plural/internal/resource"
1314

1415
"github.com/hashicorp/terraform-plugin-framework-validators/boolvalidator"
@@ -158,8 +159,8 @@ func (p *PluralProvider) Configure(ctx context.Context, req provider.ConfigureRe
158159

159160
internalClient := internalclient.NewClient(consoleClient)
160161

161-
resp.ResourceData = internalClient
162-
resp.DataSourceData = internalClient
162+
resp.ResourceData = model.NewProviderData(internalClient, consoleUrl)
163+
resp.DataSourceData = model.NewProviderData(internalClient, consoleUrl)
163164
}
164165

165166
func (p *PluralProvider) Resources(_ context.Context) []func() resource.Resource {

internal/resource/cluster.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"fmt"
66

7+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
8+
79
"terraform-provider-plural/internal/client"
810
"terraform-provider-plural/internal/model"
911

@@ -28,7 +30,8 @@ func NewClusterResource() resource.Resource {
2830

2931
// ClusterResource defines the cluster resource implementation.
3032
type clusterResource struct {
31-
client *client.Client
33+
client *client.Client
34+
consoleUrl string
3235
}
3336

3437
func (r *clusterResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
@@ -67,6 +70,8 @@ func (r *clusterResource) Schema(_ context.Context, _ resource.SchemaRequest, re
6770
"protect": schema.BoolAttribute{
6871
MarkdownDescription: "If set to `true` then this cluster cannot be deleted.",
6972
Optional: true,
73+
Computed: true,
74+
Default: booldefault.StaticBool(false),
7075
},
7176
"tags": schema.MapAttribute{
7277
MarkdownDescription: "Key-value tags used to filter clusters.",
@@ -83,7 +88,7 @@ func (r *clusterResource) Configure(_ context.Context, req resource.ConfigureReq
8388
return
8489
}
8590

86-
c, ok := req.ProviderData.(*client.Client)
91+
data, ok := req.ProviderData.(*model.ProviderData)
8792
if !ok {
8893
resp.Diagnostics.AddError(
8994
"Unexpected Cluster Resource Configure Type",
@@ -92,7 +97,8 @@ func (r *clusterResource) Configure(_ context.Context, req resource.ConfigureReq
9297
return
9398
}
9499

95-
r.client = c
100+
r.client = data.Client
101+
r.consoleUrl = data.ConsoleUrl
96102
}
97103

98104
func (r *clusterResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
@@ -127,10 +133,11 @@ func (r *clusterResource) Create(ctx context.Context, req resource.CreateRequest
127133
return
128134
}
129135

130-
// TODO:
131-
// deployToken := *cluster.CreateCluster.DeployToken
132-
// url := fmt.Sprintf("%s/ext/gql", p.ConsoleClient.Url())
133-
// p.doInstallOperator(url, deployToken)
136+
err = doInstallOperator(ctx, data.Kubeconfig, r.consoleUrl, *cluster.CreateCluster.DeployToken)
137+
if err != nil {
138+
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to install operator, got error: %s", err))
139+
return
140+
}
134141

135142
tflog.Trace(ctx, "installed the cluster operator")
136143
}

0 commit comments

Comments
 (0)