Skip to content

Commit

Permalink
PLT-726: updated docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikchern committed Oct 11, 2023
1 parent de687b5 commit 77580f0
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 239 deletions.
32 changes: 13 additions & 19 deletions docs/data-sources/cluster_profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,33 @@ output "same" {

- `context` (String)
- `name` (String)
- `pack` (Block List) (see [below for nested schema](#nestedblock--pack))
- `version` (String)

### Read-Only

- `id` (String) The ID of this resource.
- `pack` (List of Object) (see [below for nested schema](#nestedatt--pack))

<a id="nestedblock--pack"></a>
<a id="nestedatt--pack"></a>
### Nested Schema for `pack`

Required:

- `name` (String) The name of the pack. The name must be unique within the cluster profile.

Optional:
Read-Only:

- `manifest` (Block List) (see [below for nested schema](#nestedblock--pack--manifest))
- `registry_uid` (String) The registry UID of the pack. The registry UID is the unique identifier of the registry. This attribute is required if there is more than one registry that contains a pack with the same name.
- `tag` (String) The tag of the pack. The tag is the version of the pack. This attribute is required if the pack type is `spectro` or `helm`.
- `type` (String) The type of the pack. Allowed values are `spectro`, `manifest` or `helm`. The default value is `spectro`.
- `uid` (String) The unique identifier of the pack. The value can be looked up using the [`spectrocloud_pack`](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) data source. This value is required if the pack type is `spectro`.
- `values` (String) The values of the pack. The values are the configuration values of the pack. The values are specified in YAML format.
- `manifest` (List of Object) (see [below for nested schema](#nestedobjatt--pack--manifest))
- `name` (String)
- `registry_uid` (String)
- `tag` (String)
- `type` (String)
- `uid` (String)
- `values` (String)

<a id="nestedblock--pack--manifest"></a>
<a id="nestedobjatt--pack--manifest"></a>
### Nested Schema for `pack.manifest`

Required:

- `content` (String) The content of the manifest. The content is the YAML content of the manifest.
- `name` (String) The name of the manifest. The name must be unique within the pack.

Read-Only:

- `content` (String)
- `name` (String)
- `uid` (String)


2 changes: 1 addition & 1 deletion docs/resources/addon_deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ description: |-

### Required

- `cluster_context` (String)
- `cluster_uid` (String)
- `context` (String)

### Optional

Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster_import.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ resource "spectrocloud_cluster_import" "cluster" {
### Optional

- `cluster_profile` (Block List) (see [below for nested schema](#nestedblock--cluster_profile))
- `context` (String) The context of the cluster. Can be `project` or `tenant`. Default is `project`.
- `tags` (Set of String) A list of tags to be applied to the cluster. Tags must be in the form of `key:value`.
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))

Expand Down
219 changes: 0 additions & 219 deletions spectrocloud/cluster_common_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package spectrocloud

import (
"fmt"
"github.com/stretchr/testify/assert"
"reflect"
"testing"

Expand Down Expand Up @@ -271,220 +269,3 @@ func TestUpdateClusterRBAC(t *testing.T) {
t.Errorf("Expected 'invalid Context set - invalid', got %v", err)
}
}

func TestFlattenScanPolicy(t *testing.T) {
driverSpec := map[string]models.V1ComplianceScanDriverSpec{
"kube-bench": {
Config: &models.V1ComplianceScanConfig{
Schedule: &models.V1ClusterFeatureSchedule{
ScheduledRunTime: "daily",
},
},
},
"kube-hunter": {
Config: &models.V1ComplianceScanConfig{
Schedule: &models.V1ClusterFeatureSchedule{
ScheduledRunTime: "hourly",
},
},
},
"sonobuoy": {
Config: &models.V1ComplianceScanConfig{
Schedule: &models.V1ClusterFeatureSchedule{
ScheduledRunTime: "weekly",
},
},
},
}

expected := []interface{}{
map[string]interface{}{
"configuration_scan_schedule": "daily",
"penetration_scan_schedule": "hourly",
"conformance_scan_schedule": "weekly",
},
}

result := flattenScanPolicy(driverSpec)

if !reflect.DeepEqual(result, expected) {
t.Errorf("Result does not match expected. Got %v, expected %v", result, expected)
}
}

func TestGetEmptyScanPolicy(t *testing.T) {
result := getEmptyScanPolicy()

expected := &models.V1ClusterComplianceScheduleConfig{
KubeBench: &models.V1ClusterComplianceScanKubeBenchScheduleConfig{Schedule: &models.V1ClusterFeatureSchedule{ScheduledRunTime: ""}},
KubeHunter: &models.V1ClusterComplianceScanKubeHunterScheduleConfig{Schedule: &models.V1ClusterFeatureSchedule{ScheduledRunTime: ""}},
Sonobuoy: &models.V1ClusterComplianceScanSonobuoyScheduleConfig{Schedule: &models.V1ClusterFeatureSchedule{ScheduledRunTime: ""}},
}

if !reflect.DeepEqual(result, expected) {
t.Errorf("Result does not match expected. Got %v, expected %v", result, expected)
}
}

func TestFlattenBackupPolicy(t *testing.T) {
policy := &models.V1ClusterBackupConfig{
Schedule: &models.V1ClusterFeatureSchedule{ScheduledRunTime: "daily"},
BackupLocationUID: "location-123",
BackupPrefix: "backup-prefix",
Namespaces: []string{"namespace1", "namespace2"},
DurationInHours: 24,
IncludeAllDisks: true,
IncludeClusterResources: true,
}

expected := []interface{}{
map[string]interface{}{
"schedule": "daily",
"backup_location_id": "location-123",
"prefix": "backup-prefix",
"namespaces": []string{"namespace1", "namespace2"},
"expiry_in_hour": int64(24),
"include_disks": true,
"include_cluster_resources": true,
},
}

result := flattenBackupPolicy(policy)
assert.Equal(t, expected, result)
}

func TestToBackupPolicy(t *testing.T) {
// Create a ResourceData to simulate Terraform state
resourceData := resourceClusterAws().TestResourceData()
backupPolicy := []interface{}{
map[string]interface{}{
"backup_location_id": "location-123",
"prefix": "backup-prefix",
"expiry_in_hour": 24,
"include_disks": true,
"include_cluster_resources": true,
"namespaces": []interface{}{"namespace1"},
"schedule": "daily",
},
}
resourceData.Set("backup_policy", backupPolicy)

result := toBackupPolicy(resourceData)

expected := &models.V1ClusterBackupConfig{
BackupLocationUID: "location-123",
BackupPrefix: "backup-prefix",
DurationInHours: 24,
IncludeAllDisks: true,
IncludeClusterResources: true,
Namespaces: []string{"namespace1"},
Schedule: &models.V1ClusterFeatureSchedule{
ScheduledRunTime: "daily",
},
}

assert.Equal(t, expected, result)
}

func TestToScanPolicy(t *testing.T) {
// Create a ResourceData to simulate Terraform state
resourceData := resourceClusterAws().TestResourceData()

scanPolicy := []interface{}{
map[string]interface{}{
"configuration_scan_schedule": "daily",
"penetration_scan_schedule": "hourly",
"conformance_scan_schedule": "weekly",
},
}
resourceData.Set("scan_policy", scanPolicy)
result := toScanPolicy(resourceData)

expected := &models.V1ClusterComplianceScheduleConfig{
KubeBench: &models.V1ClusterComplianceScanKubeBenchScheduleConfig{
Schedule: &models.V1ClusterFeatureSchedule{ScheduledRunTime: "daily"},
},
KubeHunter: &models.V1ClusterComplianceScanKubeHunterScheduleConfig{
Schedule: &models.V1ClusterFeatureSchedule{ScheduledRunTime: "hourly"},
},
Sonobuoy: &models.V1ClusterComplianceScanSonobuoyScheduleConfig{
Schedule: &models.V1ClusterFeatureSchedule{ScheduledRunTime: "weekly"},
},
}

assert.Equal(t, expected, result)
}

func TestToPolicies(t *testing.T) {
// Create a ResourceData to simulate Terraform state
resourceData := resourceClusterAws().TestResourceData()
backupPolicy := []interface{}{
map[string]interface{}{
"backup_location_id": "location-123",
"prefix": "backup-prefix",
"expiry_in_hour": 24,
"include_disks": true,
"include_cluster_resources": true,
"namespaces": []interface{}{"namespace1"},
"schedule": "daily",
},
}
resourceData.Set("backup_policy", backupPolicy)
scanPolicy := []interface{}{
map[string]interface{}{
"configuration_scan_schedule": "daily",
"penetration_scan_schedule": "hourly",
"conformance_scan_schedule": "weekly",
},
}
resourceData.Set("scan_policy", scanPolicy)

result := toPolicies(resourceData)

expected := &models.V1SpectroClusterPolicies{
BackupPolicy: &models.V1ClusterBackupConfig{
BackupLocationUID: "location-123",
BackupPrefix: "backup-prefix",
DurationInHours: 24,
IncludeAllDisks: true,
IncludeClusterResources: true,
Namespaces: []string{"namespace1"},
Schedule: &models.V1ClusterFeatureSchedule{
ScheduledRunTime: "daily",
},
},
ScanPolicy: &models.V1ClusterComplianceScheduleConfig{
KubeBench: &models.V1ClusterComplianceScanKubeBenchScheduleConfig{
Schedule: &models.V1ClusterFeatureSchedule{ScheduledRunTime: "daily"},
},
KubeHunter: &models.V1ClusterComplianceScanKubeHunterScheduleConfig{
Schedule: &models.V1ClusterFeatureSchedule{ScheduledRunTime: "hourly"},
},
Sonobuoy: &models.V1ClusterComplianceScanSonobuoyScheduleConfig{
Schedule: &models.V1ClusterFeatureSchedule{ScheduledRunTime: "weekly"},
},
},
}

assert.Equal(t, expected, result)
}

func TestValidateContext(t *testing.T) {
// Test valid context
err := ValidateContext("project")
if err != nil {
t.Errorf("Expected no error, but got: %v", err)
}

err = ValidateContext("tenant")
if err != nil {
t.Errorf("Expected no error, but got: %v", err)
}

// Test invalid context
err = ValidateContext("invalid")
expectedError := fmt.Errorf("invalid Context set - invalid")
if err == nil || err.Error() != expectedError.Error() {
t.Errorf("Expected error: %v, but got: %v", expectedError, err)
}
}
Loading

0 comments on commit 77580f0

Please sign in to comment.