const path = require('path'); const fs = require('fs'); module.exports = { tags: async (tln) => [], dotenvs: async (tln) => [], env: async (tln, env) => {}, options: async (tln, args) => { args .prefix('TLN_K8S_COMPONENT') .option('ver', { describe: 'Version string for specific component', default: null, type: 'string' }) .option('provider', { describe: 'Cloud provider aws | azure | gcp | do', default: null, type: 'string' }) .option('cert-id', { describe: 'SSL certificate idenifier', default: null, type: 'string' }) .option('values', { describe: 'Values files', default: [], type: 'array' }) ; }, inherits: async (tln) => [], depends: async (tln) => [], steps: async (tln) => [ { id: 'nginx-ingress-install', builder: async (tln, script) => { let details = ''; let values = []; if (script.env.TLN_K8S_COMPONENT_PROVIDER) { if (script.env.TLN_K8S_COMPONENT_CERT_ID) { switch (script.env.TLN_K8S_COMPONENT_PROVIDER) { case 'aws': details = `--set controller.service.annotations."service\\.beta\\.kubernetes\\.io/aws-load-balancer-ssl-cert"=${script.env.TLN_K8S_COMPONENT_CERT_ID}`; break; case 'azure': //details = ; break; case 'gcp': //details = ; break; case 'do': details = `--set controller.service.annotations."service\\.beta\\.kubernetes\\.io/do-loadbalancer-certificate-id"=${script.env.TLN_K8S_COMPONENT_CERT_ID}`; break; } } values = (script.env.TLN_K8S_COMPONENT_VALUES.length) ? script.env.TLN_K8S_COMPONENT_VALUES : [path.join(__dirname, 'nginx-' + script.env.TLN_K8S_COMPONENT_PROVIDER + '.yaml')]; } script.set([` helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx helm repo update helm upgrade --install nginx-ingress ingress-nginx/ingress-nginx \\ --version ${script.env.TLN_K8S_COMPONENT_VER} \\ --namespace ingress-basic --create-namespace \\ --set controller.replicaCount=2 \\ --set controller.nodeSelector."kubernetes\\.io/os"=linux \\ --set defaultBackend.nodeSelector."kubernetes\\.io/os"=linux \\ --set controller.admissionWebhooks.patch.nodeSelector."kubernetes\\.io/os"=linux ${details} ${values.map(v => `-f ${v}`).join(' ')} `]); return true; } }, { id: 'nginx-ingress-status', builder: async (tln, script) => { script.set([` kubectl --namespace ingress-basic get services -o wide nginx-ingress-ingress-nginx-controller `]); } }, { id: 'nginx-ingress-ip', builder: async (tln, script) => { script.set([`kubectl --namespace ingress-basic get services nginx-ingress-ingress-nginx-controller --output jsonpath='{.status.loadBalancer.ingress[0].ip}'`]); } }, { id: 'nginx-ingress-uninstall', builder: async (tln, script) => { script.set([` helm uninstall nginx-ingress --namespace ingress-basic `]); return true; } }, { id: 'metrics-server-install', builder: async (tln, script) => { script.set([` helm repo add metrics-server https://kubernetes-sigs.github.io/metrics-server/ helm upgrade --install metrics-server metrics-server/metrics-server --version ${script.env.TLN_K8S_COMPONENT_VER} --namespace metrics-server --create-namespace `]); return true; } }, { id: 'metrics-server-status', builder: async (tln, script) => { script.set([` kubectl get all --namespace metrics-server `]); return true; } }, { id: 'metrics-server-uninstall', builder: async (tln, script) => { script.set([` helm uninstall metrics-server --namespace metrics-server `]); return true; } }, { id: 'elastic-operator-install', builder: async (tln, script) => { script.set([` helm repo add elastic https://helm.elastic.co helm upgrade --install elastic-operator elastic/eck-operator --namespace elastic-system --create-namespace --version ${script.env.TLN_K8S_COMPONENT_VER} `]); } }, { id: 'elastic-operator-status', builder: async (tln, script) => { script.set([` kubectl get all --namespace elastic-system `]); return true; } }, { id: 'elastic-operator-uninstall', builder: async (tln, script) => { script.set([` helm uninstall elastic-operator --namespace elastic-system `]); } }, ], components: async (tln) => require('./components.js').map(v => { return { id: `k8s-${v.id}` } }) }