Skip to content

Commit

Permalink
Patch and unpatch DNS configmap
Browse files Browse the repository at this point in the history
  • Loading branch information
dtomcej committed May 25, 2020
1 parent fff1f0b commit 6d05f4e
Show file tree
Hide file tree
Showing 26 changed files with 982 additions and 568 deletions.
4 changes: 4 additions & 0 deletions cmd/cleanup/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@ func cleanupCommand(cConfig *cmd.CleanupConfiguration) error {
return fmt.Errorf("error encountered during cluster cleanup: %w", err)
}

if err := c.RestoreDNSConfig(); err != nil {
return fmt.Errorf("error encountered during DNS restore: %w", err)
}

return nil
}
16 changes: 2 additions & 14 deletions cmd/prepare/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ func prepareCommand(pConfig *cmd.PrepareConfiguration) error {

p := prepare.NewPrepare(log, clients)

provider, err := p.CheckDNSProvider()
if err != nil {
return fmt.Errorf("error during cluster check: %v", err)
}

if pConfig.SMI {
log.Warnf("SMI mode is deprecated, please consider using --acl instead")
}
Expand All @@ -71,15 +66,8 @@ func prepareCommand(pConfig *cmd.PrepareConfiguration) error {
return fmt.Errorf("error during informer check: %v, this can be caused by pre-existing objects in your cluster that do not conform to the spec", err)
}

switch provider {
case prepare.CoreDNS:
if err := p.ConfigureCoreDNS(pConfig.ClusterDomain, pConfig.Namespace); err != nil {
return fmt.Errorf("unable to configure CoreDNS: %v", err)
}
case prepare.KubeDNS:
if err := p.ConfigureKubeDNS(); err != nil {
return fmt.Errorf("unable to configure KubeDNS: %v", err)
}
if err = p.ConfigureDNS(pConfig.ClusterDomain, pConfig.Namespace); err != nil {
return fmt.Errorf("unable to configure DNS: %w", err)
}

return nil
Expand Down
16 changes: 15 additions & 1 deletion helm/chart/maesh/templates/controller/hooks/cleanup-hook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,21 @@ rules:
- list
- watch
- delete

- apiGroups:
- ""
resources:
- configmaps
verbs:
- get
- update
- apiGroups:
- apps
resources:
- deployments
verbs:
- get
- update

---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
Expand Down
6 changes: 3 additions & 3 deletions integration/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (s *HelmSuite) TestACLDisabled(c *check.C) {
err := s.installHelmMaesh(c, false, false)
c.Assert(err, checker.IsNil)

defer s.unInstallHelmMaesh(c)
defer s.uninstallHelmMaesh(c)

s.waitForMaeshControllerStarted(c)
s.waitForMaeshProxyStarted(c)
Expand All @@ -37,7 +37,7 @@ func (s *HelmSuite) TestACLEnabled(c *check.C) {
err := s.installHelmMaesh(c, true, false)
c.Assert(err, checker.IsNil)

defer s.unInstallHelmMaesh(c)
defer s.uninstallHelmMaesh(c)

s.waitForMaeshControllerStarted(c)
s.waitForMaeshProxyStarted(c)
Expand All @@ -47,7 +47,7 @@ func (s *HelmSuite) TestKubeDNSEnabled(c *check.C) {
err := s.installHelmMaesh(c, false, true)
c.Assert(err, checker.IsNil)

defer s.unInstallHelmMaesh(c)
defer s.uninstallHelmMaesh(c)

s.waitForMaeshControllerStarted(c)
s.waitForMaeshProxyStarted(c)
Expand Down
4 changes: 2 additions & 2 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,9 @@ func (s *BaseSuite) installHelmMaesh(c *check.C, acl bool, kubeDNS bool) error {
return s.try.WaitCommandExecute("helm", argSlice, "powpow", 10*time.Second)
}

func (s *BaseSuite) unInstallHelmMaesh(c *check.C) {
func (s *BaseSuite) uninstallHelmMaesh(c *check.C) {
c.Log("Uninstalling Maesh via helm...")
// Install the helm chart.
// Uninstall the helm chart.
argSlice := []string{"uninstall", "powpow", "--namespace", maeshNamespace}
err := s.try.WaitCommandExecute("helm", argSlice, "uninstalled", 10*time.Second)
c.Assert(err, checker.IsNil)
Expand Down
2 changes: 2 additions & 0 deletions integration/try/try.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ func (t *Try) WaitCommandExecute(command string, argSlice []string, expected str
return fmt.Errorf("output %s does not contain %s", string(output), expected)
}

t.log.Debug(string(output))

return nil
}), ebo); err != nil {
return fmt.Errorf("unable execute command %s %s: \n%v", command, strings.Join(argSlice, " "), err)
Expand Down
29 changes: 29 additions & 0 deletions pkg/cleanup/cleanup.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package cleanup

import (
"fmt"

"github.com/containous/maesh/pkg/dns"
"github.com/containous/maesh/pkg/k8s"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -11,14 +14,18 @@ type Cleanup struct {
client k8s.Client
log logrus.FieldLogger
namespace string
dns *dns.Client
}

// NewCleanup returns an initialized cleanup object.
func NewCleanup(log logrus.FieldLogger, client k8s.Client, namespace string) *Cleanup {
dns := dns.NewClient(log, client)

return &Cleanup{
client: client,
log: log,
namespace: namespace,
dns: dns,
}
}

Expand All @@ -39,3 +46,25 @@ func (c *Cleanup) CleanShadowServices() error {

return nil
}

// RestoreDNSConfig restores the configmap and restarts the DNS pods.
func (c *Cleanup) RestoreDNSConfig() error {
provider, err := c.dns.CheckDNSProvider()
if err != nil {
return err
}

// Restore configmaps based on DNS provider.
switch provider {
case dns.CoreDNS:
if err := c.dns.RestoreCoreDNS(); err != nil {
return fmt.Errorf("unable to restore CoreDNS: %w", err)
}
case dns.KubeDNS:
if err := c.dns.RestoreKubeDNS(); err != nil {
return fmt.Errorf("unable to restore KubeDNS: %w", err)
}
}

return nil
}

0 comments on commit 6d05f4e

Please sign in to comment.