Skip to content

Commit

Permalink
Revert "helm prometheus on dind (#31)" (#32)
Browse files Browse the repository at this point in the history
This reverts commit 3edd030.
  • Loading branch information
gainsley authored Jan 31, 2019
1 parent 3edd030 commit 7beacb0
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 157 deletions.
7 changes: 0 additions & 7 deletions mexos/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,6 @@ func KubePatchServiceLocal(servicename string, ipaddr string) error {
return nil
}

// TODO: This function and createAppDNS share a lot of duplicate code,
// but are subtly different. It'd be good to consolidate and remove
// duplicate code and highlight what the different use cases are,
// since it's not clear when to use one or the other.
// This should be easier to consolidate now that kubeParam can issue
// commands locally for DIND or other cases.
// Same for KubeDeleteDNSRecords and deleteAppDNS.
func KubeAddDNSRecords(rootLB *MEXRootLB, mf *Manifest, kp *kubeParam) error {
log.DebugLog(log.DebugLevelMexos, "adding dns records for kubenernets app", "name", mf.Metadata.Name)
rootLBIPaddr, err := GetServerIPAddr(mf, mf.Values.Network.External, rootLB.Name)
Expand Down
70 changes: 18 additions & 52 deletions mexos/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package mexos

import (
"fmt"
"regexp"

"github.com/mobiledgex/edge-cloud/log"
)
Expand All @@ -23,26 +22,14 @@ func DeleteHelmAppManifest(mf *Manifest) error {
if err != nil {
return err
}
if IsLocalDIND(mf) {
// remove DNS entries
kconf, err := GetKconf(mf, false)
if err != nil {
return fmt.Errorf("error creating app due to kconf missing, %v, %v", mf, err)
}
if err = deleteAppDNS(mf, kconf); err != nil {
log.DebugLog(log.DebugLevelMexos, "warning, cannot delete DNS record", "error", err)
}
} else {
// remove DNS entries
if err = KubeDeleteDNSRecords(rootLB, mf, kp); err != nil {
log.DebugLog(log.DebugLevelMexos, "warning, cannot delete DNS record", "error", err)
}
// remove Security rules
if err = DeleteProxySecurityRules(rootLB, mf, kp.ipaddr); err != nil {
log.DebugLog(log.DebugLevelMexos, "warning, cannot delete security rules", "error", err)
}
// remove DNS entries
if err = KubeDeleteDNSRecords(rootLB, mf, kp); err != nil {
log.DebugLog(log.DebugLevelMexos, "warning, cannot delete DNS record", "error", err)
}
// remove Security rules
if err = DeleteProxySecurityRules(rootLB, mf, kp.ipaddr); err != nil {
log.DebugLog(log.DebugLevelMexos, "warning, cannot delete security rules", "error", err)
}

cmd := fmt.Sprintf("%s helm delete --purge %s", kp.kubeconfig, mf.Metadata.Name)
out, err := kp.client.Output(cmd)
if err != nil {
Expand Down Expand Up @@ -98,43 +85,22 @@ func CreateHelmAppManifest(mf *Manifest) error {
log.DebugLog(log.DebugLevelMexos, "helm tiller initialized")
}

helmOpts := ""
// XXX This gets helm's prometheus able to query kubelet metrics.
// This can be removed once Lev passes in an option in the yaml to
// set the helm command line options.
prom, err := regexp.MatchString("prometheus", mf.Metadata.Name)
if err == nil && prom {
log.DebugLog(log.DebugLevelMexos, "setting helm prometheus option")
helmOpts = "--set kubelet.serviceMonitor.https=true"
}
cmd = fmt.Sprintf("%s helm install %s --name %s %s", kp.kubeconfig, mf.Spec.Image, mf.Metadata.Name, helmOpts)
cmd = fmt.Sprintf("%s helm install %s --name %s", kp.kubeconfig, mf.Spec.Image, mf.Metadata.Name)
out, err = kp.client.Output(cmd)
if err != nil {
return fmt.Errorf("error deploying helm chart, %s, %s, %v", cmd, out, err)
}
log.DebugLog(log.DebugLevelMexos, "applied helm chart")
if IsLocalDIND(mf) {
kconf, err := GetKconf(mf, false)
if err != nil {
return fmt.Errorf("error creating app due to kconf missing, %v, %v", mf, err)
}
// Add DNS Zone
if err = createAppDNS(mf, kconf); err != nil {
log.DebugLog(log.DebugLevelMexos, "cannot add DNS entries", "error", err)
return err
}
} else {
// Add security rules
if err = AddProxySecurityRules(rootLB, mf, kp.ipaddr); err != nil {
log.DebugLog(log.DebugLevelMexos, "cannot create security rules", "error", err)
return err
}
log.DebugLog(log.DebugLevelMexos, "add spec ports", "ports", mf.Spec.Ports)
// Add DNS Zone
if err = KubeAddDNSRecords(rootLB, mf, kp); err != nil {
log.DebugLog(log.DebugLevelMexos, "cannot add DNS entries", "error", err)
return err
}
// Add security rules
if err = AddProxySecurityRules(rootLB, mf, kp.ipaddr); err != nil {
log.DebugLog(log.DebugLevelMexos, "cannot create security rules", "error", err)
return err
}
log.DebugLog(log.DebugLevelMexos, "add spec ports", "ports", mf.Spec.Ports)
// Add DNS Zone
if err = KubeAddDNSRecords(rootLB, mf, kp); err != nil {
log.DebugLog(log.DebugLevelMexos, "cannot add DNS entries", "error", err)
return err
}
return nil
}
38 changes: 34 additions & 4 deletions mexos/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"time"

sh "github.com/codeskyblue/go-sh"
"github.com/mobiledgex/edge-cloud-infra/openstack-tenant/agent/cloudflare"
"github.com/mobiledgex/edge-cloud/cloudcommon"
"github.com/mobiledgex/edge-cloud/log"
)

Expand Down Expand Up @@ -89,9 +91,9 @@ func runKubectlCreateApp(mf *Manifest, kubeManifest string) error {
if err != nil {
return fmt.Errorf("error creating app due to kconf missing, %v, %v", mf, err)
}
out, err := sh.Command("kubectl", "create", "-f", kfile, "--kubeconfig="+kconf).CombinedOutput()
out, err := sh.Command("kubectl", "create", "-f", kfile, "--kubeconfig="+kconf).Output()
if err != nil {
return fmt.Errorf("error creating app, %s, %v, %v, %s", out, err, mf, kubeManifest)
return fmt.Errorf("error creating app, %s, %v, %v", out, err, mf)
}
err = createAppDNS(mf, kconf)
if err != nil {
Expand Down Expand Up @@ -162,6 +164,12 @@ func getSvcNames(name string, kconf string) ([]string, error) {
}

func runKubectlDeleteApp(mf *Manifest, kubeManifest string) error {
if err := CheckCredentialsCF(mf); err != nil {
return err
}
if err := cloudflare.InitAPI(mexEnv(mf, "MEX_CF_USER"), mexEnv(mf, "MEX_CF_KEY")); err != nil {
return fmt.Errorf("cannot init cloudflare api, %v", err)
}
kconf, err := GetKconf(mf, false)
if err != nil {
return fmt.Errorf("error deleting app due to kconf missing, %v, %v", mf, err)
Expand All @@ -172,13 +180,35 @@ func runKubectlDeleteApp(mf *Manifest, kubeManifest string) error {
return err
}
defer os.Remove(kfile)
serviceNames, err := getSvcNames(mf.Metadata.Name, kconf)
if err != nil {
return err
}
if len(serviceNames) < 1 {
return fmt.Errorf("no service names starting with %s", mf.Metadata.Name)
}
out, err := sh.Command("kubectl", "delete", "-f", kfile, "--kubeconfig="+kconf).CombinedOutput()
if err != nil {
return fmt.Errorf("error deleting app, %s, %v, %v", out, mf, err)
}
err = deleteAppDNS(mf, kconf)
if mf.Metadata.DNSZone == "" {
return fmt.Errorf("missing dns zone, metadata %v", mf.Metadata)
}
fqdnBase := uri2fqdn(mf.Spec.URI)
dr, err := cloudflare.GetDNSRecords(mf.Metadata.DNSZone)
if err != nil {
return fmt.Errorf("error deleting dns entry for app, %v, %v", err, mf)
return fmt.Errorf("cannot get dns records for %s, %v", mf.Metadata.DNSZone, err)
}
for _, sn := range serviceNames {
fqdn := cloudcommon.ServiceFQDN(sn, fqdnBase)
for _, d := range dr {
if d.Type == "A" && d.Name == fqdn {
if err := cloudflare.DeleteDNSRecord(mf.Metadata.DNSZone, d.ID); err != nil {
return fmt.Errorf("cannot delete DNS record, %v", d)
}
log.DebugLog(log.DebugLevelMexos, "deleted DNS record", "name", fqdn)
}
}
}
return nil
}
Expand Down
3 changes: 0 additions & 3 deletions mexos/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ func ValidateKubernetesParameters(mf *Manifest, rootLB *MEXRootLB, clustName str
if mf.Values.Network.External == "" {
return nil, fmt.Errorf("validate kubernetes parameters, missing external network in platform config")
}
if IsLocalDIND(mf) {
return &kubeParam{client: &sshLocal{}}, nil
}
client, err := GetSSHClient(mf, rootLB.Name, mf.Values.Network.External, sshUser)
if err != nil {
return nil, err
Expand Down
40 changes: 12 additions & 28 deletions mexos/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,14 @@ func MEXAppCreateAppManifest(mf *Manifest) error {

if IsLocalDIND(mf) {
masteraddr := dind.GetMasterAddr()
log.DebugLog(log.DebugLevelMexos, "call AddNginxProxy for dind")

if len(mf.Spec.Ports) > 0 {
log.DebugLog(log.DebugLevelMexos, "call AddNginxProxy for dind", "ports", mf.Spec.Ports)
if err = AddNginxProxy(mf, "localhost", mf.Metadata.Name, masteraddr, mf.Spec.Ports, dind.GetDockerNetworkName(mf.Values.Cluster.Name)); err != nil {
log.DebugLog(log.DebugLevelMexos, "cannot add nginx proxy", "name", mf.Metadata.Name, "ports", mf.Spec.Ports)
return err
}
if err = AddNginxProxy(mf, "localhost", mf.Metadata.Name, masteraddr, mf.Spec.Ports, dind.GetDockerNetworkName(mf.Values.Cluster.Name)); err != nil {
log.DebugLog(log.DebugLevelMexos, "cannot add nginx proxy", "name", mf.Metadata.Name, "ports", mf.Spec.Ports)
return err
}
log.DebugLog(log.DebugLevelMexos, "call runKubectlCreateApp for dind")
var err error
if appDeploymentType == cloudcommon.AppDeploymentTypeKubernetes {
err = runKubectlCreateApp(mf, kubeManifest)
} else if appDeploymentType == cloudcommon.AppDeploymentTypeHelm {
err = CreateHelmAppManifest(mf)
} else {
err = fmt.Errorf("invalid deployment type %s for dind", appDeploymentType)
}
err := runKubectlCreateApp(mf, kubeManifest)
if err != nil {
log.DebugLog(log.DebugLevelMexos, "error creating dind app", "mf", mf)
return err
Expand Down Expand Up @@ -222,25 +213,18 @@ func MEXAppDeleteAppManifest(mf *Manifest) error {
}
if IsLocalDIND(mf) {
log.DebugLog(log.DebugLevelMexos, "run kubectl delete app for dind")
var err error
if appDeploymentType == cloudcommon.AppDeploymentTypeKubernetes {
err = runKubectlDeleteApp(mf, kubeManifest)
} else if appDeploymentType == cloudcommon.AppDeploymentTypeHelm {
err = DeleteHelmAppManifest(mf)
} else {
err = fmt.Errorf("invalid deployment type %s for dind", appDeploymentType)
}
err := runKubectlDeleteApp(mf, kubeManifest)
if err != nil {
return err
}

if len(mf.Spec.Ports) > 0 {
log.DebugLog(log.DebugLevelMexos, "call DeleteNginxProxy for dind")
if err = DeleteNginxProxy(mf, "localhost", mf.Metadata.Name); err != nil {
log.DebugLog(log.DebugLevelMexos, "cannot delete nginx proxy", "name", mf.Metadata.Name)
return err
}
log.DebugLog(log.DebugLevelMexos, "call DeleteNginxProxy for dind")

if err = DeleteNginxProxy(mf, "localhost", mf.Metadata.Name); err != nil {
log.DebugLog(log.DebugLevelMexos, "cannot delete nginx proxy", "name", mf.Metadata.Name)
return err
}

return nil

}
Expand Down
63 changes: 0 additions & 63 deletions mexos/sshlocal.go

This file was deleted.

0 comments on commit 7beacb0

Please sign in to comment.