Skip to content

Commit

Permalink
Fixed toAddonDeplProfiles cluster_context and context corrections wit…
Browse files Browse the repository at this point in the history
…h unittest fix
  • Loading branch information
SivaanandM committed Oct 6, 2023
1 parent 161ef0f commit 26105b5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
7 changes: 7 additions & 0 deletions spectrocloud/cluster_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,10 @@ func ValidationNodeRepaveIntervalForControlPlane(nodeRepaveInterval int) error {
}
return nil
}

func ValidateContext(context string) error {
if context != "project" && context != "tenant" {
return fmt.Errorf("invalid Context set - %s", context)
}
return nil
}
12 changes: 6 additions & 6 deletions spectrocloud/cluster_common_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ func toAddonDeplProfiles(c *client.V1Client, d *schema.ResourceData) ([]*models.
if uid, ok := d.GetOk("cluster_uid"); ok && uid != nil {
clusterUid = uid.(string) //d.Get("cluster_uid").(string)
}
if ct, ok := d.GetOk("cluster_context"); ok && c != nil {
clusterContext = ct.(string) //d.Get("cluster_context").(string)
}
// handling cluster day 2 addon profile operation flow
if clusterUid == "" {
clusterUid = d.Id()
}
if clusterContext == "" {
clusterContext = d.Get("context").(string)
if ct, ok := d.GetOk("context"); ok && c != nil {
clusterContext = ct.(string)
}
err := ValidateContext(clusterContext)
if err != nil {
return nil, err
}

return toProfilesCommon(c, d, clusterUid, clusterContext)
}

Expand Down
2 changes: 1 addition & 1 deletion spectrocloud/provider_resource_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func prepareAddonDeploymentTestData(id string) *schema.ResourceData {

// Set the cluster_uid, cluster_context, and apply_setting fields
d.Set("cluster_uid", "cluster-123")
d.Set("cluster_context", "tenant")
d.Set("context", "tenant")
d.Set("apply_setting", "test-setting")

// Set up the cluster_profile field
Expand Down
8 changes: 4 additions & 4 deletions spectrocloud/resource_cluster_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func resourceAddonDeployment() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"cluster_context": {
"context": {
Type: schema.TypeString,
Required: true,
},
Expand Down Expand Up @@ -65,7 +65,7 @@ func resourceAddonDeploymentCreate(ctx context.Context, d *schema.ResourceData,
var diags diag.Diagnostics

clusterUid := d.Get("cluster_uid").(string)
clusterScope := d.Get("cluster_context").(string)
clusterScope := d.Get("context").(string)

cluster, err := c.GetCluster(clusterScope, clusterUid)
if err != nil && cluster == nil {
Expand Down Expand Up @@ -141,7 +141,7 @@ func resourceAddonDeploymentRead(_ context.Context, d *schema.ResourceData, m in
var diags diag.Diagnostics

clusterUid := d.Get("cluster_uid").(string)
clusterScope := d.Get("cluster_context").(string)
clusterScope := d.Get("context").(string)
cluster, err := c.GetCluster(clusterScope, clusterUid)
if err != nil {
return diag.FromErr(err)
Expand All @@ -163,7 +163,7 @@ func resourceAddonDeploymentUpdate(ctx context.Context, d *schema.ResourceData,
c := m.(*client.V1Client)

clusterUid := d.Get("cluster_uid").(string)
clusterScope := d.Get("cluster_context").(string)
clusterScope := d.Get("context").(string)

cluster, err := c.GetCluster(clusterScope, clusterUid)
if err != nil && cluster == nil {
Expand Down

0 comments on commit 26105b5

Please sign in to comment.