Skip to content

Commit

Permalink
Merge pull request #2 from nvtkaszpir/refactor
Browse files Browse the repository at this point in the history
[WIP] Refactor
  • Loading branch information
xr1337 authored Jul 10, 2019
2 parents d4c0ff4 + 2c4a364 commit cd7e15e
Showing 1 changed file with 236 additions and 17 deletions.
253 changes: 236 additions & 17 deletions autocomplete.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,245 @@
import sublime_plugin
import sublime

key_list = ["apiVersion", "kind", "metadata","creationTimestamp","name","spec","status","spec","type","ports","port","targetPort","selector","replicas","matchLabels","template","labels","containers","image","containerPort","readinessProbe","httpGet","path","livenessProbe","protocol","subsets","addresses","ip","externalName","clusterIP","loadBalancerIP","ingress","loadBalancer","annotations","externalIPs","revision","items","sleep","env","value","command","envFrom","imagePullPolicy","lifecycle","resources","securityContext","capabilities","stdin","stdinOnce","terminationMessagePath","terminationMessagePolicy","tty","volumeDevices","volumeMounts","mountPath","workingDir","concurrencyPolicy","failedJobsHistoryLimit","jobTemplate","schedule","startingDeadlineSeconds","successfulJobsHistoryLimit","suspend","lastScheduleTime","active","minReadySeconds","revisionHistoryLimit","updateStrategy","collisionCount","conditions","currentNumberScheduled","desiredNumberScheduled","numberAvailable","numberMisscheduled","numberReady","numberUnavailable","observedGeneration","updatedNumberScheduled","paused","progressDeadlineSeconds","strategy","availableReplicas","readyReplicas","unavailableReplicas","updatedReplicas","rollingUpdate","activeDeadlineSeconds","affinity","automountServiceAccountToken","dnsConfig","dnsPolicy","hostAliases","hostIPC","hostNetwork","hostPID","hostname","imagePullSecrets","initContainers","nodeName","nodeSelector","priority","priorityClassName","readinessGates","restartPolicy","schedulerName","serviceAccount","serviceAccountName","shareProcessNamespace","subdomain","terminationGracePeriodSeconds","tolerations","volumes","requests","limits","minReplicas","maxReplicas","metrics", "targetAverageUtilization", "scaleTargetRef",]
annotation_list = ["service.beta.kubernetes.io/aws-load-balancer-type","service.beta.kubernetes.io/aws-load-balancer-internal","service.beta.kubernetes.io/aws-load-balancer-proxy-protocol","service.beta.kubernetes.io/aws-load-balancer-access-log-emit-interval","service.beta.kubernetes.io/aws-load-balancer-access-log-enabled","service.beta.kubernetes.io/aws-load-balancer-access-log-s3-bucket-name","service.beta.kubernetes.io/aws-load-balancer-access-log-s3-bucket-prefix","service.beta.kubernetes.io/aws-load-balancer-connection-draining-enabled","service.beta.kubernetes.io/aws-load-balancer-connection-draining-timeout","service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout","service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled","service.beta.kubernetes.io/aws-load-balancer-extra-security-groups","service.beta.kubernetes.io/aws-load-balancer-security-groups","service.beta.kubernetes.io/aws-load-balancer-ssl-cert","service.beta.kubernetes.io/aws-load-balancer-ssl-ports","service.beta.kubernetes.io/aws-load-balancer-ssl-negotiation-policy","service.beta.kubernetes.io/aws-load-balancer-backend-protocol","service.beta.kubernetes.io/aws-load-balancer-additional-resource-tags","service.beta.kubernetes.io/aws-load-balancer-healthcheck-healthy-threshold","service.beta.kubernetes.io/aws-load-balancer-healthcheck-unhealthy-threshold","service.beta.kubernetes.io/aws-load-balancer-healthcheck-timeout","service.beta.kubernetes.io/aws-load-balancer-healthcheck-interval", "external-dns.alpha.kubernetes.io/hostname","external-dns.alpha.kubernetes.io/ttl","alb.ingress.kubernetes.io/scheme","alb.ingress.kubernetes.io/target-type", "alb.ingress.kubernetes.io/subnets", "alb.ingress.kubernetes.io/tags","alb.ingress.kubernetes.io/listen-ports","alb.ingress.kubernetes.io/ssl-policy", "alb.ingress.kubernetes.io/unhealthy-threshold-count","alb.ingress.kubernetes.io/load-balancer-attributes", "alb.ingress.kubernetes.io/certificate-arn","alb.ingress.kubernetes.io/backend-protocol","alb.ingress.kubernetes.io/healthcheck-interval-seconds","alb.ingress.kubernetes.io/healthcheck-path","alb.ingress.kubernetes.io/healthcheck-port","alb.ingress.kubernetes.io/healthcheck-protocol","alb.ingress.kubernetes.io/healthcheck-timeout-seconds","alb.ingress.kubernetes.io/healthy-threshold-count","alb.ingress.kubernetes.io/target-group-attributes"]
value_list = ["Namespace", "LoadBalancer","Pod","Service","ConfigMap"]
# to which code scopes apply the code
scopes = ["source.yaml"]

# syntax keys
key_list = [
"accessModes",
"active",
"activeDeadlineSeconds",
"addresses",
"affinity",
"annotations",
"apiGroups",
"apiVersion",
"app",
"automountServiceAccountToken",
"availableReplicas",
"capabilities",
"clusterIP",
"collisionCount",
"command",
"concurrencyPolicy",
"conditions",
"containerPort",
"containers",
"cpu",
"creationTimestamp",
"currentNumberScheduled",
"desiredNumberScheduled",
"dnsConfig",
"dnsPolicy",
"env",
"envFrom",
"exec",
"externalIPs",
"externalName",
"failedJobsHistoryLimit",
"fieldPath",
"fieldRef",
"hostAliases",
"hostIPC",
"hostname",
"hostNetwork",
"hostPID",
"httpGet",
"image",
"imagePullPolicy",
"imagePullSecrets",
"ingress",
"initContainers",
"initialDelaySeconds",
"ip",
"items",
"jobTemplate",
"key",
"kind",
"labels",
"labelSelector",
"lastScheduleTime",
"lifecycle",
"limits",
"livenessProbe",
"loadBalancer",
"loadBalancerIP",
"matchExpressions",
"matchLabels",
"maxReplicas",
"memory",
"metadata",
"metrics",
"minAvailable",
"minReadySeconds",
"minReplicas",
"mountPath",
"name",
"nodeName",
"nodeSelector",
"numberAvailable",
"numberMisscheduled",
"numberReady",
"numberUnavailable",
"observedGeneration",
"operator",
"path",
"paused",
"periodSeconds",
"persistentVolumeClaimSpec",
"port",
"ports",
"postStart",
"preferredDuringSchedulingIgnoredDuringExecution",
"preStop",
"priority",
"priorityClassName",
"progressDeadlineSeconds",
"protocol",
"readinessGates",
"readinessProbe",
"readyReplicas",
"replicas",
"requests",
"requiredDuringSchedulingIgnoredDuringExecution",
"resources",
"restartPolicy",
"revision",
"revisionHistoryLimit",
"rollingUpdate",
"rules",
"scaleTargetRef",
"schedule",
"schedulerName",
"securityContext",
"selector",
"serviceAccount",
"serviceAccountName",
"shareProcessNamespace",
"sleep",
"spec",
"startingDeadlineSeconds",
"status",
"stdin",
"stdinOnce",
"storage",
"storageClassName",
"strategy",
"subdomain",
"subsets",
"successfulJobsHistoryLimit",
"suspend",
"targetAverageUtilization",
"targetPort",
"template",
"terminationGracePeriodSeconds",
"terminationMessagePath",
"terminationMessagePolicy",
"timeoutSeconds",
"tolerations",
"topologyKey",
"tty",
"type",
"unavailableReplicas",
"updatedNumberScheduled",
"updatedReplicas",
"updateStrategy",
"value",
"valueFrom",
"values",
"verbs",
"volumeDevices",
"volumeMounts",
"volumes",
"workingDir",
]

# annotations completions
annotation_list = [
"alb.ingress.kubernetes.io/backend-protocol",
"alb.ingress.kubernetes.io/certificate-arn",
"alb.ingress.kubernetes.io/healthcheck-interval-seconds",
"alb.ingress.kubernetes.io/healthcheck-path",
"alb.ingress.kubernetes.io/healthcheck-port",
"alb.ingress.kubernetes.io/healthcheck-protocol",
"alb.ingress.kubernetes.io/healthcheck-timeout-seconds",
"alb.ingress.kubernetes.io/healthy-threshold-count",
"alb.ingress.kubernetes.io/listen-ports",
"alb.ingress.kubernetes.io/load-balancer-attributes",
"alb.ingress.kubernetes.io/scheme",
"alb.ingress.kubernetes.io/ssl-policy",
"alb.ingress.kubernetes.io/subnets",
"alb.ingress.kubernetes.io/tags",
"alb.ingress.kubernetes.io/target-group-attributes",
"alb.ingress.kubernetes.io/target-type",
"alb.ingress.kubernetes.io/unhealthy-threshold-count",
"app.kubernetes.io/component",
"app.kubernetes.io/instance",
"app.kubernetes.io/managed-by",
"app.kubernetes.io/name",
"app.kubernetes.io/part-of",
"app.kubernetes.io/version",
"external-dns.alpha.kubernetes.io/hostname",
"external-dns.alpha.kubernetes.io/ttl",
"service.beta.kubernetes.io/aws-load-balancer-access-log-emit-interval",
"service.beta.kubernetes.io/aws-load-balancer-access-log-enabled",
"service.beta.kubernetes.io/aws-load-balancer-access-log-s3-bucket-name",
"service.beta.kubernetes.io/aws-load-balancer-access-log-s3-bucket-prefix",
"service.beta.kubernetes.io/aws-load-balancer-additional-resource-tags",
"service.beta.kubernetes.io/aws-load-balancer-backend-protocol",
"service.beta.kubernetes.io/aws-load-balancer-connection-draining-enabled",
"service.beta.kubernetes.io/aws-load-balancer-connection-draining-timeout",
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout",
"service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled",
"service.beta.kubernetes.io/aws-load-balancer-extra-security-groups",
"service.beta.kubernetes.io/aws-load-balancer-healthcheck-healthy-threshold",
"service.beta.kubernetes.io/aws-load-balancer-healthcheck-interval",
"service.beta.kubernetes.io/aws-load-balancer-healthcheck-timeout",
"service.beta.kubernetes.io/aws-load-balancer-healthcheck-unhealthy-threshold",
"service.beta.kubernetes.io/aws-load-balancer-internal",
"service.beta.kubernetes.io/aws-load-balancer-proxy-protocol",
"service.beta.kubernetes.io/aws-load-balancer-security-groups",
"service.beta.kubernetes.io/aws-load-balancer-ssl-cert",
"service.beta.kubernetes.io/aws-load-balancer-ssl-negotiation-policy",
"service.beta.kubernetes.io/aws-load-balancer-ssl-ports",
"service.beta.kubernetes.io/aws-load-balancer-type",
]

value_list = [
"Always",
"ClusterRole",
"ClusterRoleBinding",
"ConfigMap",
"CronJob",
"DaemonSet",
"Deployment",
"IfNotPresent",
"Job",
"LoadBalancer",
"Namespace",
"Pod",
"PodDisruptionBudget",
"ReplicaSet",
"ReplicationController",
"Service",
"ServiceAccount",
"StatefulSet",
]


class KubernetesManifestCompletions(sublime_plugin.EventListener):
def __init__(self):
self.class_completions = [("%s \tKubernetes Keys" % s, s) for s in key_list]
self.value_completions = [("%s \tKubernetes Values" % s, s) for s in value_list]
self.annotation_completions = [("%s \tKubernetes Annotations" % s, s) for s in annotation_list]

self.class_completions = [("%s \tKubernetes Keys" % s, s) for s in key_list]
self.value_completions = [("%s \tKubernetes Values" % s, s) for s in value_list]
self.annotation_completions = [
("%s \tKubernetes Annotations" % s, s) for s in annotation_list
]

def on_query_completions(self, view, prefix, locations):
scope = view.scope_name(view.sel()[0].b).strip()
if(scope == "source.yaml"):
line = view.substr(view.line(view.sel()[0]))
if(":" not in line):
return self.class_completions + self.annotation_completions
else:
# handle this later
# return self.value_completions
return []
else:
scope = view.scope_name(view.sel()[0].b).strip()
if any(scope_name in scope for scope_name in scopes):
line = view.substr(view.line(view.sel()[0]))
if ":" not in line:
return self.class_completions + self.annotation_completions

return []

0 comments on commit cd7e15e

Please sign in to comment.