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

Introduce Actions for better Service Enablement #247

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/Masterminds/semver v1.5.0
github.com/SchwarzIT/community-stackit-go-client v1.29.11
github.com/SchwarzIT/community-stackit-go-client v1.30.1
github.com/go-test/deep v1.0.3
github.com/google/uuid v1.3.0
github.com/hashicorp/terraform-plugin-framework v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugX
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/SchwarzIT/community-stackit-go-client v1.29.11 h1:Y4VZuSn6BwEyUDRQxj/sx6C7+eO6R5IO3R4VPYeM0Hs=
github.com/SchwarzIT/community-stackit-go-client v1.29.11/go.mod h1:hlTfBNOKE1fokWE8g3KrI0AHo0SqzTKkS+LrIdhH8Qg=
github.com/SchwarzIT/community-stackit-go-client v1.30.1 h1:pD+CvhC4qACvPboT/flp92edD/hdEPAyn02apmYXjgs=
github.com/SchwarzIT/community-stackit-go-client v1.30.1/go.mod h1:hlTfBNOKE1fokWE8g3KrI0AHo0SqzTKkS+LrIdhH8Qg=
github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk=
github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE=
Expand Down
19 changes: 11 additions & 8 deletions stackit/internal/resources/kubernetes/cluster/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"context"
"fmt"
"github.com/SchwarzIT/community-stackit-go-client/pkg/services/kubernetes/v1.1/credentials"
serviceenablement "github.com/SchwarzIT/community-stackit-go-client/pkg/services/service-enablement/v1"
"net/http"
"strings"
"time"

"github.com/SchwarzIT/community-stackit-go-client/pkg/services/kubernetes/v1.1/cluster"
"github.com/SchwarzIT/community-stackit-go-client/pkg/services/kubernetes/v1.1/project"
"github.com/SchwarzIT/community-stackit-go-client/pkg/validate"
clientValidate "github.com/SchwarzIT/community-stackit-go-client/pkg/validate"
"github.com/SchwarzIT/terraform-provider-stackit/stackit/internal/common"
Expand Down Expand Up @@ -83,10 +83,12 @@ func (r Resource) preProcessConfig(diags *diag.Diagnostics, cl *Cluster) {

func (r Resource) enableProject(ctx context.Context, diags *diag.Diagnostics, cl *Cluster, timeout time.Duration) {
projectID := cl.ProjectID.ValueString()
c := r.client.Kubernetes.Project
c := r.client.ServiceEnablement

serviceID := "cloud.stackit.ske"

found := true
status, err := c.Get(ctx, projectID)
status, err := c.GetService(ctx, projectID, serviceID)
if agg := common.Validate(&diag.Diagnostics{}, status, err, "JSON200.State"); agg != nil {
if status == nil || status.StatusCode() != http.StatusNotFound {
diags.AddError("failed to fetch SKE project status", agg.Error())
Expand All @@ -96,18 +98,19 @@ func (r Resource) enableProject(ctx context.Context, diags *diag.Diagnostics, cl
}

// check if project already enabled
if found && *status.JSON200.State == project.STATE_CREATED {
if found && *status.JSON200.State == serviceenablement.ENABLED {
return
}

res, err := c.Create(ctx, projectID)
res, err := c.EnableService(ctx, projectID, serviceID)
if agg := common.Validate(diags, res, err); agg != nil {
diags.AddError("failed during SKE project init", agg.Error())
diags.AddError("failed during SKE service enablement", agg.Error())
return
}
process := res.WaitHandler(ctx, c, projectID).SetTimeout(timeout)

process := res.WaitHandler(ctx, c, projectID, serviceID).SetTimeout(timeout)
if _, err := process.WaitWithContext(ctx); err != nil {
diags.AddError("failed to verify SKE project init", err.Error())
diags.AddError("failed to verify SKE service enablement", err.Error())
return
}
}
Expand Down
Loading