Skip to content

Commit

Permalink
PLT-740: Fixed cluster common field tenant day 2 operations
Browse files Browse the repository at this point in the history
  • Loading branch information
SivaanandM committed Oct 12, 2023
1 parent b4b6eca commit 721b51c
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 18 deletions.
4 changes: 2 additions & 2 deletions spectrocloud/cluster_common_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func readCommonFields(c *client.V1Client, d *schema.ResourceData, cluster *model
}
}

if policy, err := c.GetClusterScanConfig(d.Id()); err != nil {
if policy, err := c.GetClusterScanConfig(d.Id(), ClusterContext); err != nil {

Check failure on line 44 in spectrocloud/cluster_common_fields.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

too many arguments in call to c.GetClusterScanConfig
return diag.FromErr(err), true
} else if policy != nil && policy.Spec.DriverSpec != nil {
if err := d.Set("scan_policy", flattenScanPolicy(policy.Spec.DriverSpec)); err != nil {
Expand All @@ -57,7 +57,7 @@ func readCommonFields(c *client.V1Client, d *schema.ResourceData, cluster *model
}
}

if namespace, err := c.GetClusterNamespaceConfig(d.Id()); err != nil {
if namespace, err := c.GetClusterNamespaceConfig(d.Id(), ClusterContext); err != nil {

Check failure on line 60 in spectrocloud/cluster_common_fields.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

too many arguments in call to c.GetClusterNamespaceConfig
return diag.FromErr(err), true
} else if namespace != nil && namespace.Items != nil {
if err := d.Set("namespaces", flattenClusterNamespaces(namespace.Items)); err != nil {
Expand Down
7 changes: 6 additions & 1 deletion spectrocloud/cluster_common_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ func flattenSourceRanges(hostConfig *models.V1HostClusterConfig) string {

func updateHostConfig(c *client.V1Client, d *schema.ResourceData) error {
if hostConfigs := toClusterHostConfigs(d); hostConfigs != nil {
return c.ApplyClusterHostConfig(d.Id(), &models.V1HostClusterConfigEntity{
clusterContext := d.Get("context").(string)
err := ValidateContext(clusterContext)
if err != nil {
return err
}
return c.ApplyClusterHostConfig(d.Id(), clusterContext, &models.V1HostClusterConfigEntity{

Check failure on line 114 in spectrocloud/cluster_common_host.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

too many arguments in call to c.ApplyClusterHostConfig
HostClusterConfig: hostConfigs,
})
}
Expand Down
5 changes: 4 additions & 1 deletion spectrocloud/cluster_common_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ func flattenLocationConfig(location *models.V1ClusterLocation) []interface{} {

func updateLocationConfig(c *client.V1Client, d *schema.ResourceData) error {
clusterContext := d.Get("context").(string)

err := ValidateContext(clusterContext)
if err != nil {
return err
}
if locationConfigs := toClusterLocationConfigs(d); locationConfigs != nil {
return c.ApplyClusterLocationConfig(clusterContext, d.Id(), &models.V1SpectroClusterLocationInputEntity{
Location: locationConfigs,
Expand Down
14 changes: 12 additions & 2 deletions spectrocloud/cluster_common_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import (
)

func updateClusterMetadata(c *client.V1Client, d *schema.ResourceData) error {
return c.UpdateClusterMetadata(d.Id(), toUpdateClusterMetadata(d))
clusterContext := d.Get("context").(string)
err := ValidateContext(clusterContext)
if err != nil {
return err
}
return c.UpdateClusterMetadata(d.Id(), clusterContext, toUpdateClusterMetadata(d))

Check failure on line 15 in spectrocloud/cluster_common_metadata.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

too many arguments in call to c.UpdateClusterMetadata
}

func toUpdateClusterMetadata(d *schema.ResourceData) *models.V1ObjectMetaInputEntitySchema {
Expand All @@ -17,7 +22,12 @@ func toUpdateClusterMetadata(d *schema.ResourceData) *models.V1ObjectMetaInputEn
}

func updateClusterAdditionalMetadata(c *client.V1Client, d *schema.ResourceData) error {
return c.UpdateAdditionalClusterMetadata(d.Id(), toUpdateClusterAdditionalMetadata(d))
clusterContext := d.Get("context").(string)
err := ValidateContext(clusterContext)
if err != nil {
return err
}
return c.UpdateAdditionalClusterMetadata(d.Id(), clusterContext, toUpdateClusterAdditionalMetadata(d))

Check failure on line 30 in spectrocloud/cluster_common_metadata.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

too many arguments in call to c.UpdateAdditionalClusterMetadata
}

func toUpdateClusterAdditionalMetadata(d *schema.ResourceData) *models.V1ClusterMetaAttributeEntity {
Expand Down
7 changes: 6 additions & 1 deletion spectrocloud/cluster_common_namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ func flattenClusterNamespaces(items []*models.V1ClusterNamespaceResource) []inte

func updateClusterNamespaces(c *client.V1Client, d *schema.ResourceData) error {
if namespaces := toClusterNamespaces(d); namespaces != nil {
return c.ApplyClusterNamespaceConfig(d.Id(), namespaces)
clusterContext := d.Get("context").(string)
err := ValidateContext(clusterContext)
if err != nil {
return err
}
return c.ApplyClusterNamespaceConfig(d.Id(), clusterContext, namespaces)

Check failure on line 82 in spectrocloud/cluster_common_namespaces.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

too many arguments in call to c.ApplyClusterNamespaceConfig
}
return nil
}
20 changes: 18 additions & 2 deletions spectrocloud/cluster_common_ospatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,28 @@ import (

func updateClusterOsPatchConfig(c *client.V1Client, d *schema.ResourceData) error {
machineConfig := toMachineManagementConfig(d)
if machineConfig != nil {
return c.UpdateClusterOsPatchConfig(d.Id(), toUpdateOsPatchEntityClusterRbac(machineConfig.OsPatchConfig))
clusterContext := d.Get("context").(string)
err := ValidateContext(clusterContext)
if err != nil {
return err
}
if machineConfig.OsPatchConfig != nil {
return c.UpdateClusterOsPatchConfig(d.Id(), clusterContext, toUpdateOsPatchEntityClusterRbac(machineConfig.OsPatchConfig))

Check failure on line 23 in spectrocloud/cluster_common_ospatch.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

too many arguments in call to c.UpdateClusterOsPatchConfig
} else {
return c.UpdateClusterOsPatchConfig(d.Id(), clusterContext, toUpdateOsPatchEntityClusterRbac(getDefaultOsPatchConfig().OsPatchConfig))

Check failure on line 25 in spectrocloud/cluster_common_ospatch.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

too many arguments in call to c.UpdateClusterOsPatchConfig
}
return nil
}

func getDefaultOsPatchConfig() *models.V1MachineManagementConfig {
return &models.V1MachineManagementConfig{
OsPatchConfig: &models.V1OsPatchConfig{
PatchOnBoot: false,
RebootIfRequired: false,
},
}
}

func toUpdateOsPatchEntityClusterRbac(config *models.V1OsPatchConfig) *models.V1OsPatchEntity {
return &models.V1OsPatchEntity{
OsPatchConfig: config,
Expand Down
10 changes: 5 additions & 5 deletions spectrocloud/cluster_common_rbac.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package spectrocloud

import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/spectrocloud/hapi/models"
Expand Down Expand Up @@ -135,12 +134,13 @@ func flattenClusterRBAC(items []*models.V1ClusterRbac) []interface{} {
}

func updateClusterRBAC(c *client.V1Client, d *schema.ResourceData) error {
ClusterContext := d.Get("context").(string)
if ClusterContext != "project" && ClusterContext != "tenant" {
return fmt.Errorf("invalid Context set - %s", ClusterContext)
clusterContext := d.Get("context").(string)
err := ValidateContext(clusterContext)
if err != nil {
return err
}
if rbacs := toClusterRBACsInputEntities(d); rbacs != nil {
return c.ApplyClusterRbacConfig(d.Id(), rbacs, ClusterContext)
return c.ApplyClusterRbacConfig(d.Id(), clusterContext, rbacs)

Check failure on line 143 in spectrocloud/cluster_common_rbac.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

cannot use clusterContext (variable of type string) as type []*models.V1ClusterRbacInputEntity in argument to c.ApplyClusterRbacConfig

Check failure on line 143 in spectrocloud/cluster_common_rbac.go

View workflow job for this annotation

GitHub Actions / build-with-coverage

cannot use rbacs (variable of type []*models.V1ClusterRbacInputEntity) as type string in argument to c.ApplyClusterRbacConfig
}
return nil
}
3 changes: 2 additions & 1 deletion spectrocloud/resource_cluster_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ func resourceCloudClusterImportManoifests(cluster *models.V1SpectroCluster, d *s
// Importing from Pending which isn't desired until intention is to apply the manifest locally
if len(cluster.Metadata.Labels) > 0 {
if v, ok := cluster.Metadata.Labels["apply"]; ok && v == "true" {
importManifest, err := c.GetClusterImportManifest(cluster.Metadata.UID)
context := d.Get("context").(string)
importManifest, err := c.GetClusterImportManifest(cluster.Metadata.UID, context)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions spectrocloud/schemas/backup_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ func BackupPolicySchema() *schema.Schema {
Description: "The list of cluster UIDs to include in the backup. If `include_all_clusters` is set to `true`, then all clusters will be included.",
},
"include_all_clusters": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Type: schema.TypeBool,
Optional: true,
//Default: true,
Description: "Whether to include all clusters in the backup. If set to false, only the clusters specified in `cluster_uids` will be included.",
},
},
Expand Down

0 comments on commit 721b51c

Please sign in to comment.