Skip to content

Commit eb750f4

Browse files
authored
Merge branch 'master' into machine-config-harvester-vgpu
2 parents d9d10af + 8ccd8ec commit eb750f4

8 files changed

+202
-22
lines changed

docs/guides/apps_marketplace.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,59 @@ resource "rancher2_app_v2" "rancher-istio" {
189189
}
190190
```
191191

192+
* `prometheus-federator` - Deploy Prometheus Federator
193+
194+
```hcl
195+
resource "rancher2_app_v2" "prometheus-federator" {
196+
cluster_id = "<CLUSTER_ID>"
197+
name = "prometheus-federator"
198+
namespace = "cattle-monitoring-system"
199+
repo_name = "rancher-charts"
200+
chart_name = "prometheus-federator"
201+
chart_version = "104.0.2+up0.4.2"
202+
values = <<EOF
203+
global:
204+
cattle:
205+
clusterId: <CLUSTER_ID>
206+
projectLabel: field.cattle.io/projectId
207+
psp:
208+
enabled: false
209+
systemDefaultRegistry: registry.rancher.com
210+
systemProjectId: <PROJECT_ID>
211+
url: <RANCHER_SERVER_URL>
212+
clusterName: custom
213+
rkePathPrefix: ''
214+
rkeWindowsPathPrefix: ''
215+
imagePullSecrets: []
216+
rbac:
217+
pspAnnotations: {}
218+
pspEnabled: true
219+
systemDefaultRegistry: registry.rancher.com
220+
EOF
221+
}
222+
223+
# About the variables of the values.yaml file
224+
#
225+
# CLUSTER_ID
226+
# When viewing a specific cluster in the Rancher UI, the cluster ID (formatted as c-xxxxx) is visible in the browser's URL bar
227+
# You can also get the ID through Rancher API:
228+
#
229+
# curl -s "https://${RANCHER_SERVER}/v3/clusters?name=${CLUSTER_NAME}" \
230+
# -H 'content-type: application/json' \
231+
# -H "Authorization: Bearer $APITOKEN" \
232+
# --insecure | jq -r .data[0].id
233+
#
234+
#
235+
# PROJECT_ID
236+
# Go to Cluster Management>Explore>Cluster>Projects/Namespaces
237+
# then go to the ellipsis button (three dots) to the right of the project name and select "View YAML."
238+
# In the displayed YAML, the metadata.name field contains the Rancher Project ID (formatted as p-xxxxx)
239+
#
240+
#
241+
# RANCHER_SERVER_URL
242+
# It's the protocol and hostname of your Rancher server, e.g. https://rancher.my.org, configured during the installation with Helm
243+
```
244+
192245
* `rancher-cis-benchmark` - Deploy Rancher cis benchmark
193246

194247
```hcl

docs/resources/cluster.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ resource "rancher2_cluster" "foo-imported" {
2222

2323
### Creating Rancher v2 imported cluster with custom configuration. For Rancher v2.11.x and above.
2424

25+
This configuration can be used to indicate that system images (such as the rancher-agent) should be pulled from an unauthenticated private registry. This can be used for all imported cluster types, including imported hosted clusters (AKS, EKS, GKE).
26+
2527
```hcl
2628
# Create a new rancher2 imported Cluster with custom configuration
2729
resource "rancher2_cluster" "foo-imported" {
@@ -411,6 +413,32 @@ resource "rancher2_cluster" "foo" {
411413
}
412414
```
413415

416+
### Importing EKS cluster to Rancher v2, using `eks_config_v2`, while specifying an unauthenticated private registry. For Rancher v2.11.0 and above.
417+
418+
```hcl
419+
resource "rancher2_cloud_credential" "foo" {
420+
name = "foo"
421+
description = "foo test"
422+
amazonec2_credential_config {
423+
access_key = "<aws-access-key>"
424+
secret_key = "<aws-secret-key>"
425+
}
426+
}
427+
resource "rancher2_cluster" "foo" {
428+
name = "foo"
429+
description = "Terraform EKS cluster"
430+
eks_config_v2 {
431+
cloud_credential_id = rancher2_cloud_credential.foo.id
432+
name = "<cluster-name>"
433+
region = "<eks-region>"
434+
imported = true
435+
}
436+
imported_config {
437+
private_registry_url = <private_registry>
438+
}
439+
}
440+
```
441+
414442
### Creating EKS cluster from Rancher v2, using `eks_config_v2`. For Rancher v2.5.x and above.
415443

416444
```hcl
@@ -509,6 +537,32 @@ resource "rancher2_cluster" "foo" {
509537
}
510538
```
511539

540+
### Importing GKE cluster from Rancher v2, using `gke_config_v2`, while specifying an unauthenticated private registry. For Rancher v2.11.0 above.
541+
542+
```hcl
543+
resource "rancher2_cloud_credential" "foo-google" {
544+
name = "foo-google"
545+
description= "Terraform cloudCredential acceptance test"
546+
google_credential_config {
547+
auth_encoded_json = file(<GOOGLE_AUTH_ENCODED_JSON>)
548+
}
549+
}
550+
551+
resource "rancher2_cluster" "foo" {
552+
name = "foo"
553+
description = "Terraform imported GKE cluster"
554+
gke_config_v2 {
555+
name = "foo"
556+
google_credential_secret = rancher2_cloud_credential.foo-google.id
557+
region = <region> # Zone argument could also be used instead of region
558+
project_id = <project-id>
559+
imported = true
560+
}
561+
imported_config {
562+
private_registry_url = <private_registry>
563+
}
564+
}
565+
```
512566
### Creating GKE cluster from Rancher v2, using `gke_config_v2`. For Rancher v2.5.8 and above.
513567

514568
**Note:** At the moment, routed-based GKE clusters are not supported due to [rancher/issues/32585](https://github.com/rancher/rancher/issues/32585)
@@ -568,6 +622,34 @@ resource "rancher2_cluster" "foo" {
568622
}
569623
```
570624

625+
### Importing AKS cluster from Rancher v2, using `aks_config_v2`, while specifying an unauthenticated private registry. For Rancher v2.11.0 and above.
626+
627+
```hcl
628+
resource "rancher2_cloud_credential" "foo-aks" {
629+
name = "foo-aks"
630+
azure_credential_config {
631+
client_id = "<client-id>"
632+
client_secret = "<client-secret>"
633+
subscription_id = "<subscription-id>"
634+
}
635+
}
636+
# For imported AKS clusters, don't add any other aks_config_v2 field
637+
resource "rancher2_cluster" "foo" {
638+
name = <cluster-name>
639+
description = "Terraform AKS cluster"
640+
aks_config_v2 {
641+
cloud_credential_id = rancher2_cloud_credential.foo-aks.id
642+
resource_group = "<resource-group>"
643+
resource_location = "<resource-location"
644+
imported = true
645+
}
646+
imported_config {
647+
private_registry_url = "<private_registry>"
648+
}
649+
}
650+
```
651+
652+
571653
### Creating AKS cluster from Rancher v2, using `aks_config_v2`. For Rancher v2.6.0 and above.
572654

573655
```hcl

rancher2/data_source_rancher2_cluster.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ func dataSourceRancher2Cluster() *schema.Resource {
170170
Type: schema.TypeMap,
171171
Computed: true,
172172
},
173+
"imported_config": {
174+
Type: schema.TypeList,
175+
Computed: true,
176+
Elem: &schema.Resource{
177+
Schema: clusterImportedConfigFields(),
178+
},
179+
},
173180
},
174181
}
175182
}

rancher2/import_rancher2_namespace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func resourceRancher2NamespaceImport(d *schema.ResourceData, meta interface{}) (
1919

2020
client, err := meta.(*Config).ClusterClient(clusterID)
2121
if err != nil {
22-
log.Printf("[INFO] Problem getting cluster client for cluster with id \"%s\"", clusterID)
22+
log.Printf("[ERROR] Problem getting cluster client for cluster with id \"%s\"", clusterID)
2323
return []*schema.ResourceData{}, err
2424
}
2525

rancher2/resource_rancher2_cluster.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ func resourceRancher2Cluster() *schema.Resource {
4848
}
4949
}
5050

51+
// Allow the configuration of the imported_config field only if the
52+
// cluster is an imported generic cluster or an imported hosted cluster (e.g. AKS, GKE, EKS).
53+
// Previously defined 'conflictsWith' entries already handle other cluster types (rke, rke2, k3s)
54+
// so they do not need to be reconsidered here.
55+
importCnf, ok := d.Get("imported_config").([]interface{})
56+
if ok && len(importCnf) > 0 && !isImportedCluster(d) {
57+
return fmt.Errorf("The rancher2_cluster.imported_config field can only be used when working with generic imported clusters or imported hosted clusters (e.g. AKS, GKE, EKS)")
58+
}
59+
5160
return nil
5261
},
5362
Schema: clusterFields(),
@@ -547,7 +556,11 @@ func isKubeConfigValid(c *Config, config string) (string, bool, error) {
547556
if err != nil {
548557
return "", false, fmt.Errorf("checking Kubeconfig: %v", err)
549558
}
550-
_, err = kubernetes.NewForConfig(kubeconfig)
559+
client, err := kubernetes.NewForConfig(kubeconfig)
560+
if err != nil {
561+
return token, false, nil
562+
}
563+
_, err = client.DiscoveryClient.ServerVersion()
551564
if err != nil {
552565
return token, false, nil
553566
}
@@ -671,3 +684,32 @@ func getClusterKubeconfig(c *Config, id, origconfig string) (*managementClient.G
671684
}
672685
}
673686
}
687+
688+
func isImportedCluster(d *schema.ResourceDiff) bool {
689+
eks := d.Get("eks_config_v2")
690+
newEksArray, ok := eks.([]interface{})
691+
isEks := ok && len(newEksArray) > 0
692+
if isEks {
693+
return expandClusterEKSConfigV2(newEksArray).Imported
694+
}
695+
696+
gke := d.Get("gke_config_v2")
697+
newGkeArray, ok := gke.([]interface{})
698+
isGke := ok && len(newGkeArray) > 0
699+
if isGke {
700+
return expandClusterGKEConfigV2(newGkeArray).Imported
701+
}
702+
703+
aks := d.Get("aks_config_v2")
704+
newAksArray, ok := aks.([]interface{})
705+
isAks := ok && len(newAksArray) > 0
706+
if isAks {
707+
return expandClusterAKSConfigV2(newAksArray).Imported
708+
}
709+
710+
// if this is a generic imported cluster,
711+
// we should always allow for the field to be used.
712+
// Other non-imported cluster types (rke, rke2, k3s, etc.)
713+
// are already being blocked via the static ConflictsWith field.
714+
return true
715+
}

rancher2/schema_cluster.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ func clusterFields() map[string]*schema.Schema {
335335
MaxItems: 1,
336336
Optional: true,
337337
Computed: true,
338-
ConflictsWith: []string{"aks_config_v2", "gke_config_v2", "k3s_config", "rke_config", "oke_config", "rke2_config", "imported_config"},
338+
ConflictsWith: []string{"aks_config_v2", "gke_config_v2", "k3s_config", "rke_config", "oke_config", "rke2_config"},
339339
Elem: &schema.Resource{
340340
Schema: clusterEKSConfigV2Fields(),
341341
},
@@ -344,7 +344,7 @@ func clusterFields() map[string]*schema.Schema {
344344
Type: schema.TypeList,
345345
MaxItems: 1,
346346
Optional: true,
347-
ConflictsWith: []string{"eks_config_v2", "gke_config_v2", "k3s_config", "rke_config", "oke_config", "rke2_config", "imported_config"},
347+
ConflictsWith: []string{"eks_config_v2", "gke_config_v2", "k3s_config", "rke_config", "oke_config", "rke2_config"},
348348
Elem: &schema.Resource{
349349
Schema: clusterAKSConfigV2Fields(),
350350
},
@@ -353,7 +353,7 @@ func clusterFields() map[string]*schema.Schema {
353353
Type: schema.TypeList,
354354
MaxItems: 1,
355355
Optional: true,
356-
ConflictsWith: []string{"aks_config_v2", "eks_config_v2", "k3s_config", "rke_config", "oke_config", "rke2_config", "imported_config"},
356+
ConflictsWith: []string{"aks_config_v2", "eks_config_v2", "k3s_config", "rke_config", "oke_config", "rke2_config"},
357357
Elem: &schema.Resource{
358358
Schema: clusterGKEConfigV2Fields(),
359359
},
@@ -371,7 +371,7 @@ func clusterFields() map[string]*schema.Schema {
371371
Type: schema.TypeList,
372372
MaxItems: 1,
373373
Optional: true,
374-
ConflictsWith: []string{"aks_config_v2", "eks_config_v2", "gke_config_v2", "k3s_config", "rke_config", "oke_config", "rke2_config"},
374+
ConflictsWith: []string{"k3s_config", "rke_config", "oke_config", "rke2_config"},
375375
Elem: &schema.Resource{
376376
Schema: clusterImportedConfigFields(),
377377
},

rancher2/schema_cluster_eks_config_v2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func clusterEKSConfigV2NodeGroupsLaunchTemplateFields() map[string]*schema.Schem
5858
"version": {
5959
Type: schema.TypeInt,
6060
Optional: true,
61-
Default: 1,
61+
Computed: true,
6262
Description: "The EKS node group launch template version",
6363
},
6464
}

rancher2/schema_cluster_v2_rke_config_machine_pool.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package rancher2
22

33
import (
4-
"strings"
5-
64
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
75
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
86
"github.com/rancher/rancher/pkg/capr"
@@ -154,26 +152,24 @@ func clusterV2RKEConfigMachinePoolFields() map[string]*schema.Schema {
154152
"machine_labels": {
155153
Type: schema.TypeMap,
156154
Optional: true,
157-
Computed: true,
158-
Description: "Labels of the machine",
159-
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
160-
// Suppressing diff for labels containing cattle.io/
161-
if (strings.Contains(k, commonAnnotationLabelCattle) || strings.Contains(k, commonAnnotationLabelRancher)) && new == "" {
162-
return true
163-
}
164-
return false
165-
},
155+
Description: "Labels for the machine pool nodes",
166156
},
167157
"hostname_length_limit": {
168158
Type: schema.TypeInt,
169159
Optional: true,
170160
Description: "maximum length for autogenerated hostname",
171161
ValidateFunc: validation.IntBetween(capr.MinimumHostnameLengthLimit, capr.MaximumHostnameLengthLimit),
172162
},
173-
}
174-
175-
for k, v := range commonAnnotationLabelFields() {
176-
s[k] = v
163+
"annotations": {
164+
Type: schema.TypeMap,
165+
Optional: true,
166+
Description: "Annotations for the MachineDeployment object",
167+
},
168+
"labels": {
169+
Type: schema.TypeMap,
170+
Optional: true,
171+
Description: "Labels for the MachineDeployment object",
172+
},
177173
}
178174

179175
return s

0 commit comments

Comments
 (0)