Skip to content

Commit

Permalink
removed unneccesary response
Browse files Browse the repository at this point in the history
  • Loading branch information
1hachandr committed Jan 18, 2024
1 parent 586b9c6 commit b9f8efc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
7 changes: 6 additions & 1 deletion internal/kmi/identityclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ func (client *KMIRestClient) SaveIdentityEngine(account string, engineName strin
return err
}

_, err = client.httpclient.Post(idenityengineurl, "application/xml", bytes.NewBuffer(out))
resp, err := client.httpclient.Post(idenityengineurl, "application/xml", bytes.NewBuffer(out))
if err != nil {
return err
}
defer resp.Body.Close()
// go write error handling code for 200
if resp.StatusCode != http.StatusNoContent {
return fmt.Errorf("error while calling SaveIdentityEngine api %s and payload is %v", resp.Status, resp)
}
return nil
}

Expand Down
50 changes: 29 additions & 21 deletions internal/provider/engine_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ func (r *engineResource) Schema(_ context.Context, _ resource.SchemaRequest, res
Required: true,
Description: "The Linode region to which cluster belongs to curl -s https://api.linode.com/v4/regions/ | jq .data[].id ",
},
"kubernetes_service_account": schema.StringAttribute{
Computed: true,
},
},
},
},
Expand All @@ -97,7 +94,7 @@ func (r *engineResource) Create(ctx context.Context, req resource.CreateRequest,
var plan EngineResourceModel
diags := req.Plan.Get(ctx, &plan)
tflog.SetField(ctx, "Plan Engine", plan)
tflog.Debug(ctx, "Getting Identity engine")
tflog.Debug(ctx, "Creating Identity engine")
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
Expand Down Expand Up @@ -182,14 +179,27 @@ func (r *engineResource) Read(ctx context.Context, req resource.ReadRequest, res
}

kmiserviceAcc := kmiprojection.KubernetesServiceAccount.Text
k8ServiceAccount := strings.Split(kmiserviceAcc, ":")[3]
k8Namepace := strings.Split(kmiserviceAcc, ":")[2]
var k8ServiceAccount = ""
var k8Namepace = ""
k8String := strings.Split(kmiserviceAcc, ":")
// check if the service account is in the format system:serviceaccount:namespace:serviceaccount
if len(k8String) != 4 {

resp.Diagnostics.AddError(
"Error Reading Identity Engine",
"Could not create Identity, unexpected error: "+err.Error(),
)
}
//check if length of the string is 4
if len(k8String) > 3 {
k8Namepace = strings.Split(kmiserviceAcc, ":")[2]
}

wrkmodel := WorkloadResourceModel{
Name: types.StringValue(kmiprojection.Projection),
KubernetesServiceAccount: types.StringValue(kmiserviceAcc),
ServiceAccount: types.StringValue(k8ServiceAccount),
Namespace: types.StringValue(k8Namepace),
Region: types.StringValue(kmiprojection.Region.Text),
Name: types.StringValue(kmiprojection.Projection),
ServiceAccount: types.StringValue(k8ServiceAccount),
Namespace: types.StringValue(k8Namepace),
Region: types.StringValue(kmiprojection.Region.Text),
}
state.Workloads = append(state.Workloads, wrkmodel)
}
Expand Down Expand Up @@ -271,11 +281,10 @@ func (r *engineResource) Update(ctx context.Context, req resource.UpdateRequest,
k8ServiceAccount := strings.Split(kmiserviceAcc, ":")[3]
k8Namepace := strings.Split(kmiserviceAcc, ":")[2]
wrkmodel := WorkloadResourceModel{
Name: types.StringValue(kmiprojection.Projection),
KubernetesServiceAccount: types.StringValue(kmiserviceAcc),
ServiceAccount: types.StringValue(k8ServiceAccount),
Namespace: types.StringValue(k8Namepace),
Region: types.StringValue(kmiprojection.Region.Text),
Name: types.StringValue(kmiprojection.Projection),
ServiceAccount: types.StringValue(k8ServiceAccount),
Namespace: types.StringValue(k8Namepace),
Region: types.StringValue(kmiprojection.Region.Text),
}
plan.Workloads[wrkIndex] = wrkmodel
}
Expand Down Expand Up @@ -370,9 +379,8 @@ type EngineResourceModel struct {
}

type WorkloadResourceModel struct {
Name types.String `tfsdk:"name"`
KubernetesServiceAccount types.String `tfsdk:"kubernetes_service_account"`
ServiceAccount types.String `tfsdk:"serviceaccount"`
Namespace types.String `tfsdk:"namespace"`
Region types.String `tfsdk:"region"`
Name types.String `tfsdk:"name"`
ServiceAccount types.String `tfsdk:"serviceaccount"`
Namespace types.String `tfsdk:"namespace"`
Region types.String `tfsdk:"region"`
}

0 comments on commit b9f8efc

Please sign in to comment.