Skip to content

Commit

Permalink
registry: service add clusterIP, nodePort, loadBalancer support (kube…
Browse files Browse the repository at this point in the history
…rnetes-sigs#8291)

* registry: service add clusterIP, nodePort, loadBalancer support

* modify camelcase name to underscore

* Add registry service type compatibility check
  • Loading branch information
zhengtianbao authored and nmasse-itix committed Dec 20, 2021
1 parent 697b210 commit a16aa0f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
12 changes: 12 additions & 0 deletions roles/kubernetes-apps/registry/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ registry_storage_access_mode: "ReadWriteOnce"
registry_disk_size: "10Gi"
registry_port: 5000
registry_replica_count: 1

# type of service: ClusterIP, LoadBalancer or NodePort
registry_service_type: "ClusterIP"
# you can specify your cluster IP address when registry_service_type is ClusterIP
registry_service_cluster_ip: ""
# you can specify your cloud provider assigned loadBalancerIP when registry_service_type is LoadBalancer
registry_service_loadbalancer_ip: ""
# annotations for managing Cloud Load Balancers
registry_service_annotations: {}
# you can specify the node port when registry_service_type is NodePort
registry_service_nodeport: ""

# name of kubernetes secret for registry TLS certs
registry_tls_secret: ""

Expand Down
25 changes: 25 additions & 0 deletions roles/kubernetes-apps/registry/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
---
- name: Registry | check registry_service_type value
fail:
msg: "registry_service_type can only be 'ClusterIP', 'LoadBalancer' or 'NodePort'"
when: registry_service_type not in ['ClusterIP', 'LoadBalancer', 'NodePort']

- name: Registry | Stop if registry_service_cluster_ip is defined when registry_service_type is not 'ClusterIP'
fail:
msg: "registry_service_cluster_ip support only compatible with ClusterIP."
when:
- registry_service_cluster_ip is defined and registry_service_cluster_ip != ""
- registry_service_type != "ClusterIP"

- name: Registry | Stop if registry_service_loadbalancer_ip is defined when registry_service_type is not 'LoadBalancer'
fail:
msg: "registry_service_loadbalancer_ip support only compatible with LoadBalancer."
when:
- registry_service_loadbalancer_ip is defined and registry_service_loadbalancer_ip != ""
- registry_service_type != "LoadBalancer"

- name: Registry | Stop if registry_service_nodeport is defined when registry_service_type is not 'NodePort'
fail:
msg: "registry_service_nodeport support only compatible with NodePort."
when:
- registry_service_nodeport is defined and registry_service_nodeport != ""
- registry_service_type != "NodePort"

- name: Registry | Create addon dir
file:
Expand Down
15 changes: 15 additions & 0 deletions roles/kubernetes-apps/registry/templates/registry-svc.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,25 @@ metadata:
k8s-app: registry
addonmanager.kubernetes.io/mode: Reconcile
kubernetes.io/name: "KubeRegistry"
{% if registry_service_annotations %}
annotations:
{{ registry_service_annotations | to_nice_yaml(indent=2, width=1337) | indent(width=4) }}
{% endif %}
spec:
selector:
k8s-app: registry
type: {{ registry_service_type }}
{% if registry_service_type == "ClusterIP" and registry_service_cluster_ip != "" %}
clusterIP: {{ registry_service_cluster_ip }}
{% endif %}
{% if registry_service_type == "LoadBalancer" and registry_service_loadbalancer_ip != "" %}
loadBalancerIP: {{ registry_service_loadbalancer_ip }}
{% endif %}
ports:
- name: registry
port: {{ registry_port }}
protocol: TCP
targetPort: {{ registry_port }}
{% if registry_service_type == "NodePort" and registry_service_nodeport != "" %}
nodePort: {{ registry_service_nodeport }}
{% endif %}

0 comments on commit a16aa0f

Please sign in to comment.