From f2c96d2a6b0caf4c38518342330800d7827c8cfa Mon Sep 17 00:00:00 2001 From: Lev Shvarts Date: Mon, 4 Feb 2019 15:35:40 -0800 Subject: [PATCH] Allow kubernetes application deployment without exposed ports (#30) * Allow kubernetes application without exposed ports --- mexos/kubernetes.go | 22 ++++++++++++++-------- mexos/manifest.go | 13 +++++++++++-- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/mexos/kubernetes.go b/mexos/kubernetes.go index 6c261efab..b3798a728 100644 --- a/mexos/kubernetes.go +++ b/mexos/kubernetes.go @@ -49,6 +49,10 @@ func CreateKubernetesAppManifest(mf *Manifest, kubeManifest string) error { return fmt.Errorf("error deploying kubernetes app, %s, %v", out, err) } log.DebugLog(log.DebugLevelMexos, "applied kubernetes manifest") + // we might not be exposing ports + if len(mf.Spec.Ports) < 1 { + return nil + } // Add security rules if err = AddProxySecurityRules(rootLB, mf, kp.ipaddr); err != nil { log.DebugLog(log.DebugLevelMexos, "cannot create security rules", "error", err) @@ -227,14 +231,16 @@ func DeleteKubernetesAppManifest(mf *Manifest, kubeManifest string) error { if err != nil { return err } - // Clean up security rules and nginx proxy - if err = DeleteProxySecurityRules(rootLB, mf, kp.ipaddr); err != nil { - log.DebugLog(log.DebugLevelMexos, "cannot clean up security rules", "name", mf.Metadata.Name, "rootlb", rootLB.Name, "error", err) - } - // Clean up DNS entries - if err = KubeDeleteDNSRecords(rootLB, mf, kp); err != nil { - log.DebugLog(log.DebugLevelMexos, "cannot clean up DNS entries", "name", mf.Metadata.Name, "rootlb", rootLB.Name, "error", err) - return err + if len(mf.Spec.Ports) > 0 { + // Clean up security rules and nginx proxy + if err = DeleteProxySecurityRules(rootLB, mf, kp.ipaddr); err != nil { + log.DebugLog(log.DebugLevelMexos, "cannot clean up security rules", "name", mf.Metadata.Name, "rootlb", rootLB.Name, "error", err) + } + // Clean up DNS entries + if err = KubeDeleteDNSRecords(rootLB, mf, kp); err != nil { + log.DebugLog(log.DebugLevelMexos, "cannot clean up DNS entries", "name", mf.Metadata.Name, "rootlb", rootLB.Name, "error", err) + return err + } } log.DebugLog(log.DebugLevelMexos, "deleted deployment", "name", mf.Metadata.Name) return nil diff --git a/mexos/manifest.go b/mexos/manifest.go index a2e183dbe..0ea53709f 100644 --- a/mexos/manifest.go +++ b/mexos/manifest.go @@ -138,6 +138,15 @@ func MEXPlatformCleanManifest(mf *Manifest) error { return nil } +// Valid manifests are either v1, or apps/v1 +func kubeManifestValidApiVersion(kubeManifest string) bool { + if !strings.HasPrefix(kubeManifest, "apiVersion: v1") && + !strings.HasPrefix(kubeManifest, "apiVersion: apps/v1") { + return false + } + return true +} + //MEXAppCreateAppManifest creates app instances on the cluster platform func MEXAppCreateAppManifest(mf *Manifest) error { log.DebugLog(log.DebugLevelMexos, "create app from manifest") @@ -150,7 +159,7 @@ func MEXAppCreateAppManifest(mf *Manifest) error { if err != nil { return err } - if !strings.HasPrefix(kubeManifest, "apiVersion: v1") { + if !kubeManifestValidApiVersion(kubeManifest) { log.DebugLog(log.DebugLevelMexos, "bad apiVersion at beginning kubemanifest") return fmt.Errorf("bad apiversion at beginning of kube manifest") } @@ -374,7 +383,7 @@ func GetKubeManifest(mf *Manifest) (string, error) { deployment := mf.Config.ConfigDetail.Deployment //XXX controlling pass full yaml text in parameter of another yaml log.DebugLog(log.DebugLevelMexos, "getting kubernetes manifest", "base", base, "manifest", mani) - if deployment != cloudcommon.AppDeploymentTypeHelm && !strings.HasPrefix(mani, "apiVersion: v1") { + if deployment != cloudcommon.AppDeploymentTypeHelm && !kubeManifestValidApiVersion(mani) { fn := fmt.Sprintf("%s/%s", base, mani) log.DebugLog(log.DebugLevelMexos, "getting manifest file", "uri", fn) res, err := GetURIFile(mf, fn)