Add annotations to Kubernetes
This commit is contained in:
parent
f007f857df
commit
60bf71f6fb
3 changed files with 28 additions and 3 deletions
|
|
@ -151,6 +151,15 @@ The system will read only `host` and `port.number`
|
||||||
|
|
||||||
There is no necessary to add labels or annotations.
|
There is no necessary to add labels or annotations.
|
||||||
|
|
||||||
|
### Kubernetes annotations:
|
||||||
|
|
||||||
|
| annotation | Description | Example |
|
||||||
|
|-----------------------------|-------------------------------------------------------------------------------------------------|--------------|
|
||||||
|
| kubernetes.io/ingress.class | (required) Activate EasyHAProxy. | easyhaproxy-ingress
|
||||||
|
| easyhaproxy.redirect_ssl | (optional) Boolean. Force redirect all endpoints to https. | true/false)
|
||||||
|
| easyhaproxy.letsencrypt | (optional) Boolean. It will request letsencript certificates for the ingresses domains | true/false
|
||||||
|
| easyhaproxy.redirect | (optional) Json. Specific a domain and its destination | {"domain":"redirect_url"}
|
||||||
|
|
||||||
|
|
||||||
### Container (Docker or Swarm) labels:
|
### Container (Docker or Swarm) labels:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ class DockerLabelHandler:
|
||||||
|
|
||||||
def get_bool(self, label, default_value = False):
|
def get_bool(self, label, default_value = False):
|
||||||
if self.has_label(label):
|
if self.has_label(label):
|
||||||
return self.__data[label].lower() in ["True", "true", "1", "yes"]
|
return self.__data[label].lower() in ["true", "1", "yes"]
|
||||||
return default_value
|
return default_value
|
||||||
|
|
||||||
def get_json(self, label, default_value = {}):
|
def get_json(self, label, default_value = {}):
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,11 @@ class Kubernetes(ProcessorInterface):
|
||||||
self.v1 = client.NetworkingV1Api()
|
self.v1 = client.NetworkingV1Api()
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
def _check_annotation(self, annotations, key):
|
||||||
|
if key not in annotations:
|
||||||
|
return None
|
||||||
|
return annotations[key]
|
||||||
|
|
||||||
def inspect_network(self):
|
def inspect_network(self):
|
||||||
|
|
||||||
ret = self.v1.list_ingress_for_all_namespaces(watch=False)
|
ret = self.v1.list_ingress_for_all_namespaces(watch=False)
|
||||||
|
|
@ -144,6 +149,10 @@ class Kubernetes(ProcessorInterface):
|
||||||
if i.metadata.annotations['kubernetes.io/ingress.class'] != "easyhaproxy-ingress":
|
if i.metadata.annotations['kubernetes.io/ingress.class'] != "easyhaproxy-ingress":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
letsencrypt = self._check_annotation(i.metadata.annotations, "easyhaproxy.letsencrypt")
|
||||||
|
redirect_ssl = self._check_annotation(i.metadata.annotations, "easyhaproxy.redirect_ssl")
|
||||||
|
redirect = self._check_annotation(i.metadata.annotations, "easyhaproxy.redirect")
|
||||||
|
|
||||||
data = {}
|
data = {}
|
||||||
#ingress_name = i.metadata.name
|
#ingress_name = i.metadata.name
|
||||||
data["creation_timestamp"] = i.metadata.creation_timestamp.strftime("%x %X")
|
data["creation_timestamp"] = i.metadata.creation_timestamp.strftime("%x %X")
|
||||||
|
|
@ -156,6 +165,13 @@ class Kubernetes(ProcessorInterface):
|
||||||
rule_data["easyhaproxy.%s_%s.host" % (definition, port_number)] = rule.host
|
rule_data["easyhaproxy.%s_%s.host" % (definition, port_number)] = rule.host
|
||||||
rule_data["easyhaproxy.%s_%s.port" % (definition, port_number)] = "80"
|
rule_data["easyhaproxy.%s_%s.port" % (definition, port_number)] = "80"
|
||||||
rule_data["easyhaproxy.%s_%s.localport" % (definition, port_number)] = port_number
|
rule_data["easyhaproxy.%s_%s.localport" % (definition, port_number)] = port_number
|
||||||
|
if redirect_ssl is not None:
|
||||||
|
rule_data["easyhaproxy.%s_%s.redirect_ssl" % (definition, port_number)] = 'true'
|
||||||
|
if letsencrypt is not None:
|
||||||
|
rule_data["easyhaproxy.%s_%s.letsencrypt" % (definition, port_number)] = 'true'
|
||||||
|
if redirect is not None:
|
||||||
|
rule_data["easyhaproxy.%s_%s.redirect" % (definition, port_number)] = redirect
|
||||||
|
|
||||||
service_name = rule.http.paths[0].backend.service.name
|
service_name = rule.http.paths[0].backend.service.name
|
||||||
try:
|
try:
|
||||||
api_response = self.api_instance.read_namespaced_service(service_name, i.metadata.namespace)
|
api_response = self.api_instance.read_namespaced_service(service_name, i.metadata.namespace)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue