Skip to content

Commit

Permalink
Allow kubernetes application deployment without exposed ports (#30)
Browse files Browse the repository at this point in the history
* Allow kubernetes application without exposed ports
  • Loading branch information
levshvarts authored Feb 4, 2019
1 parent 981ccb3 commit f2c96d2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
22 changes: 14 additions & 8 deletions mexos/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions mexos/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f2c96d2

Please sign in to comment.