Skip to content

Commit

Permalink
adding new fields in clusterRepo regarding OCI support
Browse files Browse the repository at this point in the history
  • Loading branch information
diogoasouza committed Jul 18, 2024
1 parent f7e2ae9 commit 222d857
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 11 deletions.
24 changes: 24 additions & 0 deletions rancher2/data_source_rancher2_catalog_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ func dataSourceRancher2CatalogV2() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"exponential_backoff_max_wait": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Maximum amount of seconds to wait before retrying",
},
"exponential_backoff_min_wait": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Minimum amount of seconds to wait before retrying",
},
"exponential_backoff_max_retries": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Maximum number of retries before returning error",
},
"git_branch": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -35,6 +53,12 @@ func dataSourceRancher2CatalogV2() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"insecure_plain_http": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Only valid for OCI URL's. Allows insecure connections to registries without enforcing TLS checks",
},
"insecure": {
Type: schema.TypeBool,
Computed: true,
Expand Down
24 changes: 24 additions & 0 deletions rancher2/schema_catalog_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ func catalogV2Fields() map[string]*schema.Schema {
Default: true,
Description: "If disabled the repo clone will not be updated or allowed to be installed from",
},
"exponential_backoff_max_wait": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Maximum amount of seconds to wait before retrying",
},
"exponential_backoff_min_wait": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Minimum amount of seconds to wait before retrying",
},
"exponential_backoff_max_retries": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Maximum number of retries before returning error",
},
"git_branch": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -65,6 +83,12 @@ func catalogV2Fields() map[string]*schema.Schema {
Description: "Git Repository containing Helm chart definitions",
ConflictsWith: []string{"url"},
},
"insecure_plain_http": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Only valid for OCI URL's. Allows insecure connections to registries without enforcing TLS checks",
},
"insecure": {
Type: schema.TypeBool,
Optional: true,
Expand Down
42 changes: 42 additions & 0 deletions rancher2/structure_catalog_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ func flattenCatalogV2(d *schema.ResourceData, in *ClusterRepo) error {
d.Set("secret_name", in.Spec.ClientSecret.Name)
d.Set("secret_namespace", in.Spec.ClientSecret.Namespace)
}

if in.Spec.ExponentialBackOffValues != nil {
d.Set("exponential_backoff_min_wait", in.Spec.ExponentialBackOffValues.MinWait)
d.Set("exponential_backoff_max_wait", in.Spec.ExponentialBackOffValues.MaxWait)
d.Set("exponential_backoff_max_retries", in.Spec.ExponentialBackOffValues.MaxRetries)
}

d.Set("insecure_plain_http", in.Spec.InsecurePlainHTTP)

d.Set("service_account", in.Spec.ServiceAccount)
d.Set("service_account_namespace", in.Spec.ServiceAccountNamespace)
d.Set("url", in.Spec.URL)
Expand Down Expand Up @@ -96,6 +105,39 @@ func expandCatalogV2(in *schema.ResourceData) (*ClusterRepo, error) {
if v, ok := in.Get("insecure").(bool); ok {
obj.Spec.InsecureSkipTLSverify = v
}
if v, ok := in.Get("insecure_plain_http").(bool); ok {
obj.Spec.InsecurePlainHTTP = v
}
if v, ok := in.Get("exponential_backoff_min_wait").(int); ok {
if obj.Spec.ExponentialBackOffValues != nil {
obj.Spec.ExponentialBackOffValues.MinWait = v
} else {
obj.Spec.ExponentialBackOffValues = &v1.ExponentialBackOffValues{
MinWait: v,
}
}
}

if v, ok := in.Get("exponential_backoff_max_wait").(int); ok {
if obj.Spec.ExponentialBackOffValues != nil {
obj.Spec.ExponentialBackOffValues.MaxWait = v
} else {
obj.Spec.ExponentialBackOffValues = &v1.ExponentialBackOffValues{
MaxWait: v,
}
}
}

if v, ok := in.Get("exponential_backoff_max_retries").(int); ok {
if obj.Spec.ExponentialBackOffValues != nil {
obj.Spec.ExponentialBackOffValues.MaxRetries = v
} else {
obj.Spec.ExponentialBackOffValues = &v1.ExponentialBackOffValues{
MaxRetries: v,
}
}
}

sName, nok := in.Get("secret_name").(string)
sNamespace, nsok := in.Get("secret_namespace").(string)
if nok && nsok && len(sName) > 0 {
Expand Down
32 changes: 21 additions & 11 deletions rancher2/structure_catalog_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ func init() {
"label1": "one",
"label2": "two",
}
testCatalogV2Conf.Spec.ExponentialBackOffValues = &managementClient.ExponentialBackOffValues{
MinWait: 2,
MaxWait: 10,
MaxRetries: 5,
}
testCatalogV2Conf.Spec.CABundle = []byte("test DER data")
testCatalogV2Conf.Spec.Enabled = newTrue()
testCatalogV2Conf.Spec.GitBranch = "git_branch"
testCatalogV2Conf.Spec.GitRepo = "git_repo"
testCatalogV2Conf.Spec.InsecurePlainHTTP = false
testCatalogV2Conf.Spec.InsecureSkipTLSverify = false
testCatalogV2Conf.Spec.ClientSecret = &managementClient.SecretReference{
Name: "secret_name",
Expand All @@ -42,17 +48,21 @@ func init() {
testCatalogV2Conf.Spec.URL = "url"

testCatalogV2Interface = map[string]interface{}{
"name": "name",
"ca_bundle": "dGVzdCBERVIgZGF0YQ==",
"enabled": true,
"git_branch": "git_branch",
"git_repo": "git_repo",
"insecure": false,
"secret_name": "secret_name",
"secret_namespace": "secret_namespace",
"service_account": "service_account",
"service_account_namespace": "service_account_namespace",
"url": "url",
"name": "name",
"ca_bundle": "dGVzdCBERVIgZGF0YQ==",
"enabled": true,
"exponential_backoff_min_wait": 2,
"exponential_backoff_max_wait": 10,
"exponential_backoff_max_retries": 5,
"git_branch": "git_branch",
"git_repo": "git_repo",
"insecure": false,
"insecure_plain_http": false,
"secret_name": "secret_name",
"secret_namespace": "secret_namespace",
"service_account": "service_account",
"service_account_namespace": "service_account_namespace",
"url": "url",
"annotations": map[string]interface{}{
"value1": "one",
"value2": "two",
Expand Down

0 comments on commit 222d857

Please sign in to comment.