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

Let user configure kube proxy #381

Merged
merged 1 commit into from
Feb 17, 2023
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
158 changes: 150 additions & 8 deletions ovh/data_cloud_project_kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/url"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
)

func dataSourceCloudProjectKube() *schema.Resource {
Expand All @@ -29,28 +30,78 @@ func dataSourceCloudProjectKube() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
kubeClusterCustomizationKey: {
kubeClusterProxyModeKey: {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: helpers.ValidateEnum([]string{"iptables", "ipvs"}),
},
kubeClusterCustomizationApiServerKey: {
Type: schema.TypeSet,
Computed: true,
Optional: true,
// Required: true,
ForceNew: false,
MaxItems: 1,
// MaxItems: 1,
Set: CustomSchemaSetFunc(),
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"apiserver": {
"admissionplugins": {
Type: schema.TypeSet,
Computed: true,
Optional: true,
// Required: true,
ForceNew: false,
MaxItems: 1,
// MaxItems: 1,
Set: CustomSchemaSetFunc(),
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeList,
Computed: true,
Optional: true,
// Required: true,
ForceNew: false,
Elem: &schema.Schema{Type: schema.TypeString},
},
"disabled": {
Type: schema.TypeList,
Computed: true,
Optional: true,
// Required: true,
ForceNew: false,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
},
},
},
kubeClusterCustomization: {
Type: schema.TypeSet,
Computed: true,
Optional: true,
ForceNew: false,
Set: CustomSchemaSetFunc(),
Deprecated: fmt.Sprintf("Use %s instead", kubeClusterCustomizationApiServerKey),
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"apiserver": {
Type: schema.TypeSet,
Computed: true,
Optional: true,
ForceNew: false,
Set: CustomSchemaSetFunc(),
Deprecated: fmt.Sprintf("Use %s instead", kubeClusterCustomizationApiServerKey),
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"admissionplugins": {
Type: schema.TypeSet,
Computed: true,
Optional: true,
ForceNew: false,
MaxItems: 1,
Set: CustomSchemaSetFunc(),
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Expand All @@ -76,6 +127,98 @@ func dataSourceCloudProjectKube() *schema.Resource {
},
},
},
kubeClusterCustomizationKubeProxyKey: {
Type: schema.TypeSet,
Computed: false,
Optional: true,
ForceNew: false,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"iptables": {
Type: schema.TypeSet,
Computed: false,
Optional: true,
ForceNew: false,
MaxItems: 1,
Set: CustomIPVSIPTablesSchemaSetFunc(),
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"min_sync_period": {
Type: schema.TypeString,
Computed: false,
Optional: true,
ForceNew: false,
ValidateFunc: helpers.ValidateRFC3339Duration,
},
"sync_period": {
Type: schema.TypeString,
Computed: false,
Optional: true,
ForceNew: false,
ValidateFunc: helpers.ValidateRFC3339Duration,
},
},
},
},
"ipvs": {
Type: schema.TypeSet,
Computed: false,
Optional: true,
ForceNew: false,
MaxItems: 1,
Set: CustomIPVSIPTablesSchemaSetFunc(),
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"min_sync_period": {
Type: schema.TypeString,
Computed: false,
Optional: true,
ForceNew: false,
ValidateFunc: helpers.ValidateRFC3339Duration,
},
"sync_period": {
Type: schema.TypeString,
Computed: false,
Optional: true,
ForceNew: false,
ValidateFunc: helpers.ValidateRFC3339Duration,
},
"scheduler": {
Type: schema.TypeString,
Computed: false,
Optional: true,
ForceNew: false,
ValidateFunc: helpers.ValidateEnum([]string{"rr", "lc", "dh", "sh", "sed", "nq"}),
},
"tcp_fin_timeout": {
Type: schema.TypeString,
Computed: false,
Optional: true,
ForceNew: false,
ValidateFunc: helpers.ValidateRFC3339Duration,
},
"tcp_timeout": {
Type: schema.TypeString,
Computed: false,
Optional: true,
ForceNew: false,
ValidateFunc: helpers.ValidateRFC3339Duration,
},
"udp_timeout": {
Type: schema.TypeString,
Computed: false,
Optional: true,
ForceNew: false,
ValidateFunc: helpers.ValidateRFC3339Duration,
},
},
},
},
},
},
},

"private_network_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -132,12 +275,11 @@ func dataSourceCloudProjectKubeRead(d *schema.ResourceData, meta interface{}) er
url.PathEscape(serviceName),
url.PathEscape(kubeId),
)
err := config.OVHClient.Get(endpoint, res)
if err != nil {
if err := config.OVHClient.Get(endpoint, res); err != nil {
return fmt.Errorf("Error calling %s:\n\t %q", endpoint, err)
}

for k, v := range res.ToMap() {
for k, v := range res.ToMap(d) {
if k != "id" {
d.Set(k, v)
} else {
Expand Down
81 changes: 75 additions & 6 deletions ovh/data_cloud_project_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,58 @@ func TestAccCloudProjectKubeDataSource_basic(t *testing.T) {

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheckCloud(t)
testAccCheckCloudProjectExists(t)
testAccPreCheckKubernetes(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.ovh_cloud_project_kube.cluster", "region", region),
resource.TestCheckResourceAttr(
"data.ovh_cloud_project_kube.cluster", "name", name),
resource.TestMatchResourceAttr(
"data.ovh_cloud_project_kube.cluster", "version", matchVersion),
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "region", region),
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "name", name),
resource.TestMatchResourceAttr("data.ovh_cloud_project_kube.cluster", "version", matchVersion),
),
},
},
})
}

func TestAccCloudProjectKubeDataSource_kubeProxy(t *testing.T) {
name := acctest.RandomWithPrefix(test_prefix)
region := os.Getenv("OVH_CLOUD_PROJECT_KUBE_REGION_TEST")
config := fmt.Sprintf(
testAccCloudProjectKubeDatasourceKubeProxyConfig,
os.Getenv("OVH_CLOUD_PROJECT_SERVICE_TEST"),
name,
region,
)

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheckCloud(t)
testAccCheckCloudProjectExists(t)
testAccPreCheckKubernetes(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "region", region),
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "name", name),
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "kube_proxy_mode", "ipvs"),

resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "customization_kube_proxy.0.iptables.0.min_sync_period", "PT30S"),
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "customization_kube_proxy.0.iptables.0.sync_period", "PT30S"),

resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "customization_kube_proxy.0.ipvs.0.min_sync_period", "PT30S"),
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "customization_kube_proxy.0.ipvs.0.sync_period", "PT30S"),
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "customization_kube_proxy.0.ipvs.0.scheduler", "rr"),
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "customization_kube_proxy.0.ipvs.0.tcp_fin_timeout", "PT30S"),
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "customization_kube_proxy.0.ipvs.0.tcp_timeout", "PT30S"),
resource.TestCheckResourceAttr("data.ovh_cloud_project_kube.cluster", "customization_kube_proxy.0.ipvs.0.udp_timeout", "PT30S"),
),
},
},
Expand All @@ -57,3 +96,33 @@ data "ovh_cloud_project_kube" "cluster" {
kube_id = ovh_cloud_project_kube.cluster.id
}
`

var testAccCloudProjectKubeDatasourceKubeProxyConfig = `
resource "ovh_cloud_project_kube" "cluster" {
service_name = "%s"
name = "%s"
region = "%s"

kube_proxy_mode = "ipvs"
customization_kube_proxy {
iptables {
min_sync_period = "PT30S"
sync_period = "PT30S"
}

ipvs {
min_sync_period = "PT30S"
sync_period = "PT30S"
scheduler = "rr"
tcp_fin_timeout = "PT30S"
tcp_timeout = "PT30S"
udp_timeout = "PT30S"
}
}
}

data "ovh_cloud_project_kube" "cluster" {
service_name = ovh_cloud_project_kube.cluster.service_name
kube_id = ovh_cloud_project_kube.cluster.id
}
`
9 changes: 9 additions & 0 deletions ovh/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/go-ovh/ovh"
"github.com/ybriffa/rfc3339"
)

func ValidateIpBlock(value string) error {
Expand Down Expand Up @@ -186,6 +187,14 @@ func ValidateDedicatedCephStatus(value string) error {
})
}

// ValidateRFC3339Duration implements schema.SchemaValidateFunc for RFC3339 durations.
func ValidateRFC3339Duration(i interface{}, _ string) (_ []string, errors []error) {
if _, err := rfc3339.ParseDuration(i.(string)); err != nil {
errors = append(errors, err)
}
return
}

func ValidateDedicatedCephACLFamily(value string) error {
return ValidateStringEnum(value, []string{
"IPv4",
Expand Down
Loading