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

add operating system field to workerpool actions #4133

Merged
merged 5 commits into from
Nov 10, 2022
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
17 changes: 9 additions & 8 deletions ibm/flex/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,15 @@ func FlattenVpcWorkerPools(list []containerv2.GetWorkerPoolResponse) []map[strin
workerPools := make([]map[string]interface{}, len(list))
for i, workerPool := range list {
l := map[string]interface{}{
"id": workerPool.ID,
"name": workerPool.PoolName,
"flavor": workerPool.Flavor,
"worker_count": workerPool.WorkerCount,
"isolation": workerPool.Isolation,
"labels": workerPool.Labels,
"state": workerPool.Lifecycle.ActualState,
"host_pool_id": workerPool.HostPoolID,
"id": workerPool.ID,
"name": workerPool.PoolName,
"flavor": workerPool.Flavor,
"worker_count": workerPool.WorkerCount,
"isolation": workerPool.Isolation,
"labels": workerPool.Labels,
"operating_system": workerPool.OperatingSystem,
"state": workerPool.Lifecycle.ActualState,
"host_pool_id": workerPool.HostPoolID,
}
zones := workerPool.Zones
zonesConfig := make([]map[string]interface{}, len(zones))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ func DataSourceIBMContainerVpcClusterWorkerPool() *schema.Resource {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"operating_system": {
Type: schema.TypeString,
Computed: true,
Description: "The operating system of the workers in the worker pool",
},
"resource_group_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -133,6 +138,7 @@ func dataSourceIBMContainerVpcClusterWorkerPoolRead(d *schema.ResourceData, meta
d.Set("flavor", workerPool.Flavor)
d.Set("worker_count", workerPool.WorkerCount)
d.Set("labels", workerPool.Labels)
d.Set("operating_system", workerPool.OperatingSystem)
d.Set("zones", zones)
d.Set("cluster", clusterName)
d.Set("vpc_id", workerPool.VpcID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,30 @@ func testAccCheckIBMContainerVPCClusterWorkerPoolDataSourceKmsAccountEnvvar(name
}
`
}
func TestAccIBMContainerVpcOpenshiftClusterWorkerPoolDataSource(t *testing.T) {
name := fmt.Sprintf("tf-vpc-worker-%d", acctest.RandIntRange(10, 100))
openshiftFlavour := "bx2.16x64"
openShiftworkerCount := "2"
operatingSystem := "REDHAT_8_64"
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMContainerVpcOpenshiftClusterWorkerPoolDataSourceConfig(name, openshiftFlavour, openShiftworkerCount, operatingSystem),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.ibm_container_vpc_cluster_worker_pool.default_worker_pool", "operating_system", operatingSystem),
),
},
},
})
}

func testAccCheckIBMContainerVpcOpenshiftClusterWorkerPoolDataSourceConfig(name, openshiftFlavour, openShiftworkerCount, operatingSystem string) string {
return testAccCheckIBMContainerOcpClusterBasic(name, openshiftFlavour, openShiftworkerCount, operatingSystem) + `
data "ibm_container_vpc_cluster_worker_pool" "default_worker_pool" {
cluster = ibm_container_vpc_cluster.cluster.id
worker_pool_name = "default"
}
`
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ func DataSourceIBMContainerWorkerPool() *schema.Resource {
Description: "list of labels to worker pool",
},

"operating_system": {
Type: schema.TypeString,
Computed: true,
Description: "The operating system of the workers in the worker pool",
},

"resource_group_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -160,6 +166,7 @@ func dataSourceIBMContainerWorkerPoolRead(d *schema.ResourceData, meta interface
if workerPool.Labels != nil {
d.Set("labels", workerPool.Labels)
}
d.Set("operating_system", workerPool.OperatingSystem)
d.Set("zones", flex.FlattenZones(workerPool.Zones))
if strings.Contains(machineType, "encrypted") {
d.Set("disk_encryption", true)
Expand Down
12 changes: 12 additions & 0 deletions ibm/service/kubernetes/resource_ibm_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,21 @@ func ResourceIBMContainerCluster() *schema.Resource {
},
Description: "Private VLAN ID",
},

"entitlement": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: flex.ApplyOnce,
Description: "Entitlement option reduces additional OCP Licence cost in Openshift Clusters",
},

"operating_system": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The operating system of the workers in the default worker pool.",
},

"wait_for_worker_update": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -709,6 +717,9 @@ func resourceIBMContainerClusterCreate(d *schema.ResourceData, meta interface{})
if v, ok := d.GetOk("kube_version"); ok {
params.MasterVersion = v.(string)
}
if v, ok := d.GetOk("operating_system"); ok {
params.OperatingSystem = v.(string)
}
if v, ok := d.GetOkExists("private_service_endpoint"); ok {
params.PrivateEndpointEnabled = v.(bool)
}
Expand Down Expand Up @@ -865,6 +876,7 @@ func resourceIBMContainerClusterRead(d *schema.ResourceData, meta interface{}) e
return err
}
d.Set("labels", flex.IgnoreSystemLabels(defaultWorkerPool.Labels))
d.Set("operating_system", defaultWorkerPool.OperatingSystem)
zones := defaultWorkerPool.Zones
for _, zone := range zones {
if zone.ID == cls.DataCenter {
Expand Down
17 changes: 17 additions & 0 deletions ibm/service/kubernetes/resource_ibm_container_vpc_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ func ResourceIBMContainerVpcCluster() *schema.Resource {
Description: "Labels for default worker pool",
},

"operating_system": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "The operating system of the workers in the default worker pool.",
},

"taints": {
Type: schema.TypeSet,
Optional: true,
Expand Down Expand Up @@ -225,6 +232,7 @@ func ResourceIBMContainerVpcCluster() *schema.Resource {
},
},
},

"disable_public_service_endpoint": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -276,13 +284,15 @@ func ResourceIBMContainerVpcCluster() *schema.Resource {
Computed: true,
Description: "The URL of the IBM Cloud dashboard that can be used to explore and view details about this cluster",
},

"kms_instance_id": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: flex.ApplyOnce,
Description: "Instance ID for boot volume encryption",
RequiredWith: []string{"crk"},
},

"crk": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -321,6 +331,7 @@ func ResourceIBMContainerVpcCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"albs": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -361,6 +372,7 @@ func ResourceIBMContainerVpcCluster() *schema.Resource {
},
},
},

"public_service_endpoint_url": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -513,6 +525,10 @@ func resourceIBMContainerVpcClusterCreate(d *schema.ResourceData, meta interface
workerpool.HostPoolID = hpid.(string)
}

if os, ok := d.GetOk("operating_system"); ok {
workerpool.OperatingSystem = os.(string)
}

if kmsid, ok := d.GetOk("kms_instance_id"); ok {
crk := d.Get("crk").(string)
wve := v2.WorkerVolumeEncryption{
Expand Down Expand Up @@ -1025,6 +1041,7 @@ func resourceIBMContainerVpcClusterRead(d *schema.ResourceData, meta interface{}
}
d.Set("image_security_enforcement", cls.ImageSecurityEnabled)
d.Set("host_pool_id", workerPool.HostPoolID)
d.Set("operating_system", workerPool.OperatingSystem)

tags, err := flex.GetTagsUsingCRN(meta, cls.CRN)
if err != nil {
Expand Down
51 changes: 26 additions & 25 deletions ibm/service/kubernetes/resource_ibm_container_vpc_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ func TestAccIBMContainerVpcClusterBasic(t *testing.T) {
},
})
}

func TestAccIBMContainerOpenshiftClusterBasic(t *testing.T) {
name := fmt.Sprintf("tf-vpc-cluster-%d", acctest.RandIntRange(10, 100))
openshiftFlavour := "bx2.16x64"
openShiftworkerCount := "2"
operatingSystem := "REDHAT_7_64"
var conf *v2.ClusterInfo

resource.Test(t, resource.TestCase{
Expand All @@ -88,7 +90,7 @@ func TestAccIBMContainerOpenshiftClusterBasic(t *testing.T) {
CheckDestroy: testAccCheckIBMContainerVpcClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMContainerOcpClusterBasic(name, openshiftFlavour, openShiftworkerCount),
Config: testAccCheckIBMContainerOcpClusterBasic(name, openshiftFlavour, openShiftworkerCount, operatingSystem),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMContainerVpcExists("ibm_container_vpc_cluster.cluster", conf),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -332,48 +334,47 @@ resource "ibm_container_vpc_cluster" "cluster" {

}`, name)
}
func testAccCheckIBMContainerOcpClusterBasic(name, openshiftFlavour, openShiftworkerCount string) string {
func testAccCheckIBMContainerOcpClusterBasic(name, openshiftFlavour, openShiftworkerCount, operatingSystem string) string {
vpcName := "<test-vpc-name>"
subnetName := "<test-subnet-name>"
cosInstanceName := "<test-cos-name>"
return fmt.Sprintf(`
provider "ibm" {
region="eu-de"
}
region="us-south"
}
data "ibm_resource_group" "resource_group" {
is_default = "true"
is_default=true
}
resource "ibm_is_vpc" "vpc1" {
name = "%[1]s"
data "ibm_is_vpc" "vpc" {
name = "%s"
}
resource "ibm_is_subnet" "subnet" {
name = "%[1]s"
vpc = "${ibm_is_vpc.vpc1.id}"
zone = "eu-de-1"
total_ipv4_address_count = 256

data "ibm_is_subnet" "subnet" {
name = "%s"
}
resource "ibm_resource_instance" "cos_instance" {
name = "testcos_instance"
service = "cloud-object-storage"
plan = "standard"
location = "global"
data "ibm_resource_instance" "cos_instance" {
name = "%s"
}
resource "ibm_container_vpc_cluster" "cluster" {
name = "%[1]s"
vpc_id = "${ibm_is_vpc.vpc1.id}"
name = "%s"
vpc_id = data.ibm_is_vpc.vpc.id
flavor = "%s"
worker_count = "%s"
kube_version = "4.3.23_openshift"
wait_till = "IngressReady"
kube_version = "4.11_openshift"
operating_system = "%s"
wait_till = "OneWorkerNodeReady"
entitlement = "cloud_pak"
cos_instance_crn = ibm_resource_instance.cos_instance.id
cos_instance_crn = data.ibm_resource_instance.cos_instance.id
resource_group_id = data.ibm_resource_group.resource_group.id
zones {
subnet_id = ibm_is_subnet.subnet.id
name = "eu-de-1"
subnet_id = data.ibm_is_subnet.subnet.id
name = "us-south-1"
}
}
data "ibm_container_cluster_config" "testacc_ds_cluster" {
cluster_name_id = ibm_container_vpc_cluster.cluster.id
}
`, name, openshiftFlavour, openShiftworkerCount)
`, vpcName, subnetName, cosInstanceName, name, openshiftFlavour, openShiftworkerCount, operatingSystem)

}

Expand Down
19 changes: 19 additions & 0 deletions ibm/service/kubernetes/resource_ibm_container_vpc_worker_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,41 +132,55 @@ func ResourceIBMContainerVpcWorkerPool() *schema.Resource {
Description: "ID of the resource group.",
ForceNew: true,
},

"vpc_id": {
Type: schema.TypeString,
Required: true,
Description: "The vpc id where the cluster is",
ForceNew: true,
},

"worker_count": {
Type: schema.TypeInt,
Required: true,
Description: "The number of workers",
},

"entitlement": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: flex.ApplyOnce,
Description: "Entitlement option reduces additional OCP Licence cost in Openshift Clusters",
},

"operating_system": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "The operating system of the workers in the worker pool.",
},

"host_pool_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "The ID of the dedicated host pool associated with the worker pool",
},

flex.ResourceControllerURL: {
Type: schema.TypeString,
Computed: true,
Description: "Resource Controller URL",
},

"kms_instance_id": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: flex.ApplyOnce,
Description: "Instance ID for boot volume encryption",
RequiredWith: []string{"crk"},
},

"crk": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -268,6 +282,10 @@ func resourceIBMContainerVpcWorkerPoolCreate(d *schema.ResourceData, meta interf
params.Entitlement = v.(string)
}

if os, ok := d.GetOk("operating_system"); ok {
params.OperatingSystem = os.(string)
}

if hpid, ok := d.GetOk("host_pool_id"); ok {
params.HostPoolID = hpid.(string)
}
Expand Down Expand Up @@ -505,6 +523,7 @@ func resourceIBMContainerVpcWorkerPoolRead(d *schema.ResourceData, meta interfac
d.Set("resource_group_id", cls.ResourceGroupID)
d.Set("cluster", cluster)
d.Set("vpc_id", workerPool.VpcID)
d.Set("operating_system", workerPool.OperatingSystem)
d.Set("host_pool_id", workerPool.HostPoolID)
if workerPool.Taints != nil {
d.Set("taints", flattenWorkerPoolTaints(workerPool))
Expand Down
Loading