Skip to content

Instantly share code, notes, and snippets.

@gurvindersingh
Last active June 15, 2018 16:40
Show Gist options
  • Save gurvindersingh/3d361c5e0ea35fda98002bf649ea22c3 to your computer and use it in GitHub Desktop.
Save gurvindersingh/3d361c5e0ea35fda98002bf649ea22c3 to your computer and use it in GitHub Desktop.
function(request) {
local service = request.object,
// Uncommenting this cause error as
// Expected token OPERATOR but got (".", ".")
// as DecoratorController does not support status like "labels or annotations"
// service.status.loadBalancer:
// if service.spec.type == "LoadBalancer" then
// {
// ingress: [
// {
// hostname: "example.com",
// ip: "1.1.1.1",
// }
// ]
// },
// else
// service.status.loadBalancer,
// Create a service for each Pod, with a selector on the given label key.
attachments:
if service.spec.type == "LoadBalancer" then
[
{
apiVersion: "networking.k8s.io/v1",
kind: "NetworkPolicy",
metadata: {
name: service.metadata.name + "-lb",
labels: service.metadata.labels,
namespace: service.metadata.namespace,
},
spec: {
podSelector: {
matchLabels: service.spec.selector,
},
policyTypes: ["Ingress"],
ingress: [
{
from: [
{
ipBlock: {
cidr: "0.0.0.0/0",
},
},
],
ports: [
{
protocol: service.spec.ports[0].protocol,
port: service.spec.ports[0].port,
}
]
}
]
}
}
]
else
[]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment