diff --git a/experiments/debug_pod.yaml b/experiments/debug_pod.yaml new file mode 100644 index 0000000..aefeec3 --- /dev/null +++ b/experiments/debug_pod.yaml @@ -0,0 +1,49 @@ +apiVersion: v1 +kind: Pod +metadata: + name: debug-adaravis + labels: + is_ioc: "true" +spec: + serviceAccountName: default-full-access-mounted + containers: + - name: debug-adaravis + image: ghcr.io/epics-containers/ioc-adaravis-developer:2024.11.1 + command: + - bash + args: + - "-c" + - | + echo "keep running indefinetely" + while true; do sleep 5; done + resources: + limits: + memory: "2Gi" + cpu: "4" + requests: + memory: "1Gi" + cpu: "1" + + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: beamline + operator: In + values: + - bl47p + + tolerations: + - key: beamline + operator: Equal + value: bl47p + effect: NoSchedule + - key: location + operator: Equal + value: bl47p + effect: NoSchedule + - key: nodetype + operator: Equal + value: training-rig + effect: NoSchedule diff --git a/experiments/test.py b/experiments/test.py new file mode 100755 index 0000000..beb2383 --- /dev/null +++ b/experiments/test.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python + +""" +Prints out some information about the pods in a namespace +""" + +import argparse + +from kubernetes import client, config + + +def get_ioc_ips(v1: client.CoreV1Api): + """Get the list cluster IPs of IOCs running in a namespace + + Args: + v1: kubernetes client + namespace: namespace to get the IOCs from + """ + ips = set() + + # get the current namespace + ns_path = "/var/run/secrets/kubernetes.io/serviceaccount/namespace" + with open(ns_path) as f: + current_namespace = f.read().strip() + + # get the pods in the namespace + ret = v1.list_namespaced_pod(current_namespace) + for pod in ret.items: + print(pod.metadata.name, pod.status.pod_ip) + if "is_ioc" in pod.metadata.labels: + ips.add(pod.status.pod_ip) + + return ips + + +def main(): + args = parse_args() + + # configure K8S and make a Core API client + config.load_incluster_config() + v1 = client.CoreV1Api() + + ips = get_ioc_ips(v1) + ipstr = " ".join(ips) + + command = f'/epics/ca-gateway/bin/linux-x86_64/gateway -sport {args.port} -cip "{ipstr}" -pvlist /config/pvlist -access /config/access -log /dev/stdout -debug 1' + + # print(f"Running command: {command}") + # subprocess.run(["bash", "-c", command], check=True) + + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument("--port", type=int, default=5064) + return parser.parse_args() + + +if __name__ == "__main__": + main() diff --git a/services/cagateway/templates/deployment.yaml b/services/cagateway/templates/deployment.yaml index f6e7322..43f8d28 100644 --- a/services/cagateway/templates/deployment.yaml +++ b/services/cagateway/templates/deployment.yaml @@ -24,6 +24,7 @@ spec: location: bl47p rollme: goWO0 spec: + serviceAccountName: default-full-access-mounted affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: @@ -38,14 +39,12 @@ spec: - bash args: - "-c" - - "/epics/gateway -sport {{ .Values.ca_port }} -cip 172.23.255.255 -pvlist /config/pvlist -access /config/access -log /dev/stdout -debug 1" + - "python3 /launch_gateway.py --port {{ .Values.ca_port }} --namespace ${MY_POD_NAMESPACE}" env: - - name: IOC_NAME - value: {{ .Release.Name }} - - name: IOC_LOCATION - value: bl47p - - name: IOC_GROUP - value: p47 + - name: MY_POD_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace image: {{ .Values.image }} imagePullPolicy: Always name: {{ .Release.Name }} @@ -63,7 +62,7 @@ spec: volumeMounts: - mountPath: /config name: config-volume - hostNetwork: true + hostNetwork: false restartPolicy: Always terminationGracePeriodSeconds: 3 tolerations: diff --git a/services/cagateway/values.yaml b/services/cagateway/values.yaml index a156d14..be6b093 100644 --- a/services/cagateway/values.yaml +++ b/services/cagateway/values.yaml @@ -1,2 +1,2 @@ -image: ghcr.io/epics-containers/docker-ca-gateway-debug:2.1.3ec1 +image: ghcr.io/epics-containers/docker-ca-gateway-debug:2.1.3ec2b4 ca_port: 9064