Skip to content

Commit

Permalink
Merge pull request #66 from syseleven/K8s-7940-update-datacenter-api
Browse files Browse the repository at this point in the history
K8s-7940 Update the new datacenter API
  • Loading branch information
furkhat authored Feb 15, 2023
2 parents 9516ac1 + 318e609 commit 7aa1515
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 165 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/hashicorp/go-version v1.5.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.17.0
github.com/mitchellh/go-homedir v1.1.0
github.com/syseleven/go-metakube v0.0.0-20230110080853-e37d025caddf
github.com/syseleven/go-metakube v0.0.0-20230214162150-bac65fa46326
go.uber.org/zap v1.19.0
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/syseleven/go-metakube v0.0.0-20230110080853-e37d025caddf h1:k/SAqRjiAvP3dhEgLEIYY/vNCorZcJMxwyyh4EKtUfQ=
github.com/syseleven/go-metakube v0.0.0-20230110080853-e37d025caddf/go.mod h1:Wmf9qWGkFXBGAJxXuwGH+SH6eq9txahkGRpTUz/JFhY=
github.com/syseleven/go-metakube v0.0.0-20230214162150-bac65fa46326 h1:xXowml9+zi3i9DY2Hr6/9WDPWt25fwjIg3imN/LD1Ss=
github.com/syseleven/go-metakube v0.0.0-20230214162150-bac65fa46326/go.mod h1:Wmf9qWGkFXBGAJxXuwGH+SH6eq9txahkGRpTUz/JFhY=
github.com/syseleven/terraform-plugin-sdk/v2 v2.17.0-sys11-1 h1:M2c981F8TnNf8yFGD51oHNzMYcIIQ6nbySBrvUQrckM=
github.com/syseleven/terraform-plugin-sdk/v2 v2.17.0-sys11-1/go.mod h1:tunSMaRkZLxRmsJZAFXiznrk8Vl+KJ+GAfW52tQMu7w=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
Expand Down
4 changes: 2 additions & 2 deletions metakube/resource_metakube_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ func metakubeResourceClusterSSHKeys(d *schema.ResourceData) []string {

func metakubeResourceClusterFindDatacenterByName(ctx context.Context, k *metakubeProviderMeta, d *schema.ResourceData) (*models.Datacenter, diag.Diagnostics) {
name := d.Get("dc_name").(string)
p := datacenter.NewListDatacentersParams().WithContext(ctx)
r, err := k.client.Datacenter.ListDatacenters(p, k.auth)
p := datacenter.NewListDatacentersV2Params().WithContext(ctx)
r, err := k.client.Datacenter.ListDatacentersV2(p, k.auth)
if err != nil {
return nil, diag.Errorf("Can't list datacenters: %s", stringifyResponseError(err))
}
Expand Down
66 changes: 0 additions & 66 deletions metakube/resource_metakube_cluster_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,6 @@ func flattenUpdateWindow(in *models.UpdateWindow) []interface{} {
return []interface{}{m}
}

func flattenMachineNetworks(in []*models.MachineNetworkingConfig) []interface{} {
if len(in) < 1 {
return []interface{}{}
}

att := make([]interface{}, len(in))

for i, v := range in {
m := make(map[string]interface{})

if v.CIDR != "" {
m["cidr"] = v.CIDR
}
if v.Gateway != "" {
m["gateway"] = v.Gateway
}
if l := len(v.DNSServers); l > 0 {
ds := make([]interface{}, l)
for i, s := range v.DNSServers {
ds[i] = s
}
m["dns_servers"] = ds
}
att[i] = m
}

return att
}

func flattenClusterCloudSpec(values clusterPreserveValues, in *models.CloudSpec) []interface{} {
if in == nil {
return []interface{}{}
Expand Down Expand Up @@ -409,43 +380,6 @@ func expandUpdateWindow(p []interface{}) *models.UpdateWindow {
return ret
}

func expandMachineNetworks(p []interface{}) []*models.MachineNetworkingConfig {
if len(p) < 1 {
return nil
}
var machines []*models.MachineNetworkingConfig
for _, elem := range p {
in := elem.(map[string]interface{})
obj := &models.MachineNetworkingConfig{}

if v, ok := in["cidr"]; ok {
if vv, ok := v.(string); ok && v != "" {
obj.CIDR = vv
}
}

if v, ok := in["gateway"]; ok {
if vv, ok := v.(string); ok && v != "" {
obj.Gateway = vv
}
}

if v, ok := in["dns_servers"]; ok {
if vv, ok := v.([]interface{}); ok {
for _, s := range vv {
if ss, ok := s.(string); ok && s != "" {
obj.DNSServers = append(obj.DNSServers, ss)
}
}
}
}

machines = append(machines, obj)
}

return machines
}

func expandAuditLogging(enabled bool) *models.AuditLoggingSettings {
return &models.AuditLoggingSettings{
Enabled: enabled,
Expand Down
94 changes: 0 additions & 94 deletions metakube/resource_metakube_cluster_structure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func TestMetakubeClusterFlattenSpec(t *testing.T) {
Start: "Tue 02:00",
Length: "3h",
},
MachineNetworks: nil,
EnableUserSSHKeyAgent: true,
AuditLogging: &models.AuditLoggingSettings{},
Cloud: &models.CloudSpec{
Expand Down Expand Up @@ -362,51 +361,6 @@ func TestFlattenAzureCloudSpec(t *testing.T) {
}
}

func TestFlattenMachineNetwork(t *testing.T) {
cases := []struct {
Input []*models.MachineNetworkingConfig
ExpectedOutput []interface{}
}{
{
[]*models.MachineNetworkingConfig{
{
CIDR: "192.168.0.0/24",
Gateway: "192.168.1.1",
DNSServers: []string{
"192.200.200.1",
"192.200.200.201",
},
},
},
[]interface{}{
map[string]interface{}{
"cidr": "192.168.0.0/24",
"gateway": "192.168.1.1",
"dns_servers": []interface{}{
"192.200.200.1",
"192.200.200.201",
},
},
},
},
{
[]*models.MachineNetworkingConfig{},
[]interface{}{},
},
{
nil,
[]interface{}{},
},
}

for _, tc := range cases {
output := flattenMachineNetworks(tc.Input)
if diff := cmp.Diff(tc.ExpectedOutput, output); diff != "" {
t.Fatalf("Unexpected output from expander: mismatch (-want +got):\n%s", diff)
}
}
}

func TestExpandClusterSpec(t *testing.T) {
cases := []struct {
Input []interface{}
Expand Down Expand Up @@ -448,7 +402,6 @@ func TestExpandClusterSpec(t *testing.T) {
Start: "Tue 02:00",
Length: "3h",
},
MachineNetworks: nil,
AuditLogging: &models.AuditLoggingSettings{},
UsePodSecurityPolicyAdmissionPlugin: true,
UsePodNodeSelectorAdmissionPlugin: true,
Expand Down Expand Up @@ -708,53 +661,6 @@ func TestExpandAzureCloudSpec(t *testing.T) {
}
}

func TestExpandMachineNetwork(t *testing.T) {
cases := []struct {
Input []interface{}
ExpectedOutput []*models.MachineNetworkingConfig
}{
{
[]interface{}{
map[string]interface{}{
"cidr": "192.168.0.0/24",
"gateway": "192.168.1.1",
"dns_servers": []interface{}{
"192.200.200.1",
"192.200.200.201",
},
},
},
[]*models.MachineNetworkingConfig{
{
CIDR: "192.168.0.0/24",
Gateway: "192.168.1.1",
DNSServers: []string{
"192.200.200.1",
"192.200.200.201",
},
},
},
},
{
[]interface{}{
map[string]interface{}{},
},
[]*models.MachineNetworkingConfig{{}},
},
{
[]interface{}{},
nil,
},
}

for _, tc := range cases {
output := expandMachineNetworks(tc.Input)
if diff := cmp.Diff(tc.ExpectedOutput, output); diff != "" {
t.Fatalf("Unexpected output from expander: mismatch (-want +got):\n%s", diff)
}
}
}

func TestExpandAuditLogging(t *testing.T) {
want := &models.AuditLoggingSettings{
Enabled: true,
Expand Down

0 comments on commit 7aa1515

Please sign in to comment.