Skip to content

Commit

Permalink
Expose k8s private network (#219)
Browse files Browse the repository at this point in the history
* allow user to use the k8s private net

* update description of k8s_private_network_uuid

* update k8s rs docs

* deprecate network_uuid, and sec zone uuid in k8s rs

* reword k8s rs

* break loop when k8s net is found
  • Loading branch information
nvthongswansea authored Feb 23, 2023
1 parent a359c4a commit c483fb7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
28 changes: 26 additions & 2 deletions gridscale/resource_gridscale_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import (
"log"
)

const k8sTemplateFlavourName = "kubernetes"
const (
k8sTemplateFlavourName = "kubernetes"
k8sLabelPrefix = "#gsk#"
)

const (
k8sReleaseValidationOpt = iota
Expand Down Expand Up @@ -117,14 +120,21 @@ func resourceGridscaleK8s() *schema.Resource {
"security_zone_uuid": {
Type: schema.TypeString,
Description: "Security zone UUID linked to PaaS service.",
Deprecated: "Security zone is deprecated for gridSQL, gridStore, and gridFs. Please consider to use private network instead.",
Deprecated: "GSK service does not support security zone.",
Optional: true,
ForceNew: true,
Computed: true,
},
"network_uuid": {
Type: schema.TypeString,
Description: "Network UUID containing security zone",
Deprecated: `network_uuid of a security zone is no more available for GSK.
Please consider to use k8s_private_network_uuid for connecting external services to the cluster.`,
Computed: true,
},
"k8s_private_network_uuid": {
Type: schema.TypeString,
Description: "Private network UUID which k8s nodes are attached to. It can be used to attach other PaaS/VMs.",
Computed: true,
},
"release": {
Expand Down Expand Up @@ -324,6 +334,20 @@ func resourceGridscaleK8sRead(d *schema.ResourceData, meta interface{}) error {
}
}
}

k8sLabel := fmt.Sprintf("%s%s", k8sLabelPrefix, d.Id())
// look for a network having the defined k8sLabel.
NETWORK_LOOOP:
for _, network := range networks {
for _, label := range network.Properties.Labels {
if label == k8sLabel {
if err = d.Set("k8s_private_network_uuid", network.Properties.ObjectUUID); err != nil {
return fmt.Errorf("%s error setting k8s_private_network_uuid: %v", errorPrefix, err)
}
break NETWORK_LOOOP
}
}
}
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/k8s.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ This resource exports the following attributes:
* `service_template_uuid` - PaaS service template that k8s service uses. The `service_template_uuid` may not relate to `release`, if `service_template_uuid`/`release` is updated outside of terraform (e.g. the k8s service is upgraded by gridscale staffs).
* `service_template_category` - The template service's category used to create the service.
* `labels` - See Argument Reference above.
* `network_uuid` - Network UUID containing security zone, which is linked to the k8s cluster.
* `network_uuid` - *DEPRECATED* Network UUID containing security zone, which is linked to the k8s cluster.
* `k8s_private_network_uuid` - Private network UUID which k8s nodes are attached to. It can be used to attach other PaaS/VMs.
* `node_pool` - See Argument Reference above.
* `name` - See Argument Reference above.
* `node_count` - See Argument Reference above.
Expand Down

0 comments on commit c483fb7

Please sign in to comment.