Skip to content

Commit c7d611d

Browse files
authored
Merge pull request #447 from rawmind0/rancher247
Rancher 2.4.8 support and fixes
2 parents e95594a + 6a728e2 commit c7d611d

43 files changed

Lines changed: 1562 additions & 151 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
## 1.10.2 (September 10, 2020)
2+
3+
FEATURES:
4+
5+
6+
7+
ENHANCEMENTS:
8+
9+
* Updated go mod, vendor files and provider tests to support rancher 2.4.8 and k3s v1.18.8-k3s1
10+
* Added `rancher2_cluster_sync.state_confirm` argument to wait until active status is confirmed a number of times
11+
* Added `syslog_config.enable_tls` argument to cluster and project logging
12+
13+
BUG FIXES:
14+
15+
* Fix `rke_config.cloud_provider.name` argument to not be validated
16+
* Fix `rancher2_certificate` resource update
17+
* Fix false diff if `rancher2_project.project_monitoring_input` not specified
18+
* Fix `rancher2_token.ttl` argument to work properly on Rancher up to v2.4.7
19+
* Fix `rancher2_namespace.resource_quota` argument to computed
20+
* Fix `rancher2_app` resource to wait until created/updated
21+
122
## 1.10.1 (August 27, 2020)
223

324
FEATURES:

GNUmakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ upgrade-rancher:
3535

3636
vet:
3737
@echo "==> Checking that code complies with go vet requirements..."
38-
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
38+
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -gt 0 ]; then \
3939
echo ""; \
4040
echo "Vet found suspicious constructs. Please check the reported constructs"; \
4141
echo "and fix them if necessary before submitting the code for review."; \
@@ -75,5 +75,5 @@ test-compile:
7575
fi
7676
go test -c $(TEST) $(TESTARGS)
7777

78-
.PHONY: build test testacc vet fmt fmtcheck errcheck vendor-status test-compile
78+
.PHONY: build test testacc vet fmt fmtcheck errcheck vendor-status test-compile bin
7979

docs/resources/cluster.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ The following attributes are exported:
457457
* `aws_cloud_provider` - (Optional/Computed) RKE AWS Cloud Provider config for Cloud Provider [rke-aws-cloud-provider](https://rancher.com/docs/rke/latest/en/config-options/cloud-providers/aws/) (list maxitems:1)
458458
* `azure_cloud_provider` - (Optional/Computed) RKE Azure Cloud Provider config for Cloud Provider [rke-azure-cloud-provider](https://rancher.com/docs/rke/latest/en/config-options/cloud-providers/azure/) (list maxitems:1)
459459
* `custom_cloud_provider` - (Optional/Computed) RKE Custom Cloud Provider config for Cloud Provider (string)
460-
* `name` - (Optional/Computed) RKE Cloud Provider name. `aws`, `azure`, `custom`, `external`, `openstack` and `vsphere` are supported (string)
460+
* `name` - (Optional/Computed) RKE Cloud Provider name (string)
461461
* `openstack_cloud_provider` - (Optional/Computed) RKE Openstack Cloud Provider config for Cloud Provider [rke-openstack-cloud-provider](https://rancher.com/docs/rke/latest/en/config-options/cloud-providers/openstack/) (list maxitems:1)
462462
* `vsphere_cloud_provider` - (Optional/Computed) RKE Vsphere Cloud Provider config for Cloud Provider [rke-vsphere-cloud-provider](https://rancher.com/docs/rke/latest/en/config-options/cloud-providers/vsphere/) Extra argument `name` is required on `virtual_center` configuration. (list maxitems:1)
463463

docs/resources/cluster_logging.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ The following attributes are exported:
134134
* `protocol` - (Optional) Protocol for the syslog service. `tcp` and `udp` are supported. Default: `udp` (string)
135135
* `severity` - (Optional) Date format for the syslog logs. `emergency`, `alert`, `critical`, `error`, `warning`, `notice`, `info` and `debug` are supported. Default: `notice` (string)
136136
* `ssl_verify` - (Optional) SSL verify for the syslog service (bool)
137+
* `enable_tls` - (Optional) Enable TLS for the syslog service. Default `false` (bool)
137138
* `token` - (Optional/Sensitive) Token for the syslog service (string)
138139

139140
## Timeouts

docs/resources/cluster_sync.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ The following arguments are supported:
8787
* `cluster_id` - (Required/ForceNew) The cluster ID that is syncing (string)
8888
* `node_pool_ids` - (Optional) The node pool IDs used by the cluster id (list)
8989
* `wait_monitoring` - (Optional) Wait until monitoring is up and running. Default: `false` (bool)
90+
* `state_confirm` - (Optional) Wait until active status is confirmed a number of times (wait interval of 5s). Default: `1` means no confirmation (int)
9091

92+
**Note** `state_confirm` would be useful, if you have troubles for creating/updating custom clusters that eventually are reaching `active` state before they are fully installed. For example: setting `state_confirm = 2` will assure that the cluster has been in `active` state for at least 5 seconds, `state_confirm = 3` assure at least 10 seconds, etc
9193

9294
## Attributes Reference
9395

docs/resources/namespace.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ The following arguments are supported:
7070
* `project_id` - (Required) The project id where assign namespace. It's on the form `project_id=<cluster_id>:<id>`. Updating `<id>` part on same `<cluster_id>` namespace will be moved between projects (string)
7171
* `container_resource_limit` - (Optional) Default containers resource limits on namespace (List maxitem:1)
7272
* `description` - (Optional) A namespace description (string)
73-
* `resource_quota` - (Optional) Resource quota for namespace. Rancher v2.1.x or higher (list maxitems:1)
73+
* `resource_quota` - (Optional/Computed) Resource quota for namespace. Rancher v2.1.x or higher (list maxitems:1)
7474
* `wait_for_cluster` - (Optional) Wait for cluster becomes active. Default `false` (bool)
7575
* `annotations` - (Optional/Computed) Annotations for Node Pool object (map)
7676
* `labels` - (Optional/Computed) Labels for Node Pool object (map)

rancher2/0_provider_upgrade_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ resource "rancher2_namespace" "testacc" {
3636
project_id = rancher2_cluster_sync.testacc.default_project_id
3737
}
3838
`
39-
testAccCheckRancher2UpgradeVersion = []string{"v2.3.6", "v2.4.6"}
39+
testAccCheckRancher2UpgradeVersion = []string{"v2.3.6", "v2.4.8"}
4040
testAccCheckRancher2UpgradeCluster = os.Getenv("RANCHER_ACC_CLUSTER_NAME")
4141
testAccCheckRancher2UpgradeCatalogV24 = testAccRancher2CatalogGlobal + testAccRancher2CatalogCluster + testAccRancher2CatalogProject
4242
testAccCheckRancher2UpgradeCertificateV24 = testAccRancher2Certificate + testAccRancher2CertificateNs

rancher2/config.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ const (
2121
rancher2RetriesWait = 5
2222
rancher2RKEK8sSystemImageVersion = "2.3.0"
2323
rancher2NodeTemplateChangeVersion = "2.3.3" // Change node template id format
24-
rancher2TokeChangeVersion = "2.4.6" // ttl token is readed in minutes
24+
rancher2TokeTTLMinutesVersion = "2.4.6" // ttl token is readed in minutes
25+
rancher2TokeTTLMilisVersion = "2.4.7" // ttl token is readed in miliseconds
2526
rancher2NodeTemplateNewPrefix = "cattle-global-nt:nt-"
2627
)
2728

@@ -149,6 +150,22 @@ func (c *Config) fixNodeTemplateID(id string) string {
149150
return id
150151
}
151152

153+
func (c *Config) IsRancherVersionGreaterThanOrEqualAndLessThan(ver1, ver2 string) (bool, error) {
154+
_, err := c.GetRancherVersion()
155+
if err != nil {
156+
return false, fmt.Errorf("[ERROR] getting rancher server version")
157+
}
158+
greaterOrEqualThan, err := IsVersionGreaterThanOrEqual(c.RancherVersion, ver1)
159+
if err != nil {
160+
return false, err
161+
}
162+
lessThan, err := IsVersionLessThan(c.RancherVersion, ver2)
163+
if err != nil {
164+
return false, err
165+
}
166+
return (greaterOrEqualThan && lessThan), nil
167+
}
168+
152169
func (c *Config) IsRancherVersionLessThan(ver string) (bool, error) {
153170
if len(ver) == 0 {
154171
return false, fmt.Errorf("[ERROR] version is nil")
@@ -157,7 +174,7 @@ func (c *Config) IsRancherVersionLessThan(ver string) (bool, error) {
157174
if err != nil {
158175
return false, fmt.Errorf("[ERROR] getting rancher server version")
159176
}
160-
return IsVersionLessThanl(c.RancherVersion, ver)
177+
return IsVersionLessThan(c.RancherVersion, ver)
161178
}
162179

163180
func (c *Config) IsRancherVersionGreaterThanOrEqual(ver string) (bool, error) {
@@ -1416,23 +1433,23 @@ func (c *Config) CreateCertificate(cert interface{}) (interface{}, error) {
14161433
}
14171434
}
14181435

1419-
func (c *Config) updateCertificate(cert *projectClient.Certificate, update map[string]interface{}) (*projectClient.Certificate, error) {
1436+
func (c *Config) updateCertificate(cert *projectClient.Certificate, update interface{}) (*projectClient.Certificate, error) {
14201437
client, err := c.ProjectClient(cert.ProjectID)
14211438
if err != nil {
14221439
return nil, err
14231440
}
14241441
return client.Certificate.Update(cert, update)
14251442
}
14261443

1427-
func (c *Config) updateNamespacedCertificate(cert *projectClient.NamespacedCertificate, update map[string]interface{}) (*projectClient.NamespacedCertificate, error) {
1444+
func (c *Config) updateNamespacedCertificate(cert *projectClient.NamespacedCertificate, update interface{}) (*projectClient.NamespacedCertificate, error) {
14281445
client, err := c.ProjectClient(cert.ProjectID)
14291446
if err != nil {
14301447
return nil, err
14311448
}
14321449
return client.NamespacedCertificate.Update(cert, update)
14331450
}
14341451

1435-
func (c *Config) UpdateCertificate(cert interface{}, update map[string]interface{}) (interface{}, error) {
1452+
func (c *Config) UpdateCertificate(cert interface{}, update interface{}) (interface{}, error) {
14361453
if cert == nil {
14371454
return nil, fmt.Errorf("[ERROR] Certificate can't be nil")
14381455
}

rancher2/resource_rancher2_app.go

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,28 @@ func resourceRancher2AppCreate(d *schema.ResourceData, meta interface{}) error {
6565

6666
if d.Get("wait").(bool) {
6767
stateConf := &resource.StateChangeConf{
68+
Pending: []string{},
69+
Target: []string{"no"},
70+
Refresh: appTransitionRefreshFunc(client, newApp.ID),
71+
Timeout: d.Timeout(schema.TimeoutCreate),
72+
Delay: 1 * time.Second,
73+
MinTimeout: 3 * time.Second,
74+
}
75+
_, waitErr := stateConf.WaitForState()
76+
if waitErr != nil {
77+
return fmt.Errorf("[ERROR] waiting for app (%s) to finish transitioning: %s", newApp.ID, waitErr)
78+
}
79+
stateConf = &resource.StateChangeConf{
6880
Pending: []string{},
6981
Target: []string{"active"},
7082
Refresh: appStateRefreshFunc(client, newApp.ID),
7183
Timeout: d.Timeout(schema.TimeoutCreate),
7284
Delay: 1 * time.Second,
7385
MinTimeout: 3 * time.Second,
7486
}
75-
_, waitErr := stateConf.WaitForState()
87+
_, waitErr = stateConf.WaitForState()
7688
if waitErr != nil {
77-
return fmt.Errorf("[ERROR] waiting for app (%s) to be created: %s", newApp.ID, waitErr)
89+
return fmt.Errorf("[ERROR] waiting for app (%s) to be active: %s", newApp.ID, waitErr)
7890
}
7991
}
8092

@@ -177,14 +189,26 @@ func resourceRancher2AppUpdate(d *schema.ResourceData, meta interface{}) error {
177189

178190
if d.Get("wait").(bool) {
179191
stateConf := &resource.StateChangeConf{
192+
Pending: []string{"yes"},
193+
Target: []string{"no"},
194+
Refresh: appTransitionRefreshFunc(client, id),
195+
Timeout: d.Timeout(schema.TimeoutCreate),
196+
Delay: 1 * time.Second,
197+
MinTimeout: 3 * time.Second,
198+
}
199+
_, waitErr := stateConf.WaitForState()
200+
if waitErr != nil {
201+
return fmt.Errorf("[ERROR] waiting for app (%s) to finish transitioning: %s", id, waitErr)
202+
}
203+
stateConf = &resource.StateChangeConf{
180204
Pending: []string{},
181205
Target: []string{"active"},
182206
Refresh: appStateRefreshFunc(client, id),
183207
Timeout: d.Timeout(schema.TimeoutUpdate),
184208
Delay: 1 * time.Second,
185209
MinTimeout: 3 * time.Second,
186210
}
187-
_, waitErr := stateConf.WaitForState()
211+
_, waitErr = stateConf.WaitForState()
188212
if waitErr != nil {
189213
return fmt.Errorf(
190214
"[ERROR] waiting for app (%s) to be updated: %s", id, waitErr)
@@ -284,7 +308,20 @@ func appStateRefreshFunc(client *projectClient.Client, appID string) resource.St
284308
}
285309
return nil, "", err
286310
}
287-
288311
return obj, obj.State, nil
289312
}
290313
}
314+
315+
// appTransitionRefreshFunc returns a resource.StateRefreshFunc, used to watch a Rancher App.
316+
func appTransitionRefreshFunc(client *projectClient.Client, appID string) resource.StateRefreshFunc {
317+
return func() (interface{}, string, error) {
318+
obj, err := client.App.ByID(appID)
319+
if err != nil {
320+
if IsNotFound(err) || IsForbidden(err) {
321+
return obj, "no", nil
322+
}
323+
return nil, "", err
324+
}
325+
return obj, obj.Transitioning, nil
326+
}
327+
}

rancher2/resource_rancher2_certificate.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,9 @@ func resourceRancher2CertificateUpdate(d *schema.ResourceData, meta interface{})
8585
return err
8686
}
8787

88-
certs, err := Base64Decode(d.Get("certs").(string))
88+
update, err := expandCertificate(d)
8989
if err != nil {
90-
return fmt.Errorf("Updating certificate: certs is not base64 encoded")
91-
}
92-
93-
key, err := Base64Decode(d.Get("key").(string))
94-
if err != nil {
95-
return fmt.Errorf("Updating certificate: key is not base64 encoded")
96-
}
97-
98-
update := map[string]interface{}{
99-
"description": d.Get("description").(string),
100-
"certs": certs,
101-
"keys": key,
102-
"annotations": toMapString(d.Get("annotations").(map[string]interface{})),
103-
"labels": toMapString(d.Get("labels").(map[string]interface{})),
90+
return err
10491
}
10592

10693
newCertificate, err := meta.(*Config).UpdateCertificate(certificate, update)

0 commit comments

Comments
 (0)