Skip to content

Commit

Permalink
vpc dns: remove unused variable
Browse files Browse the repository at this point in the history
Signed-off-by: zhangzujian <[email protected]>
  • Loading branch information
zhangzujian committed Jul 24, 2024
1 parent 6004088 commit c78c4a9
Showing 1 changed file with 15 additions and 66 deletions.
81 changes: 15 additions & 66 deletions pkg/controller/vpc_dns.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package controller

import (
"bufio"
"bytes"
"context"
"encoding/json"
Expand Down Expand Up @@ -33,61 +32,27 @@ import (
)

var (
corednsImage = ""
corednsVip = ""
nadName = ""
nadProvider = ""
cmVersion = ""
k8sServiceHost = ""
k8sServicePort = ""
enableCoredns = false
hostNameservers []string

corednsTemplateContent = kubeovnyaml.CorednsTemplateContent
corednsImage = ""
corednsVip = ""
nadName = ""
nadProvider = ""
cmVersion = ""
k8sServiceHost = ""
k8sServicePort = ""
enableCoreDNS = false

corednsTemplateContent = string(kubeovnyaml.CorednsTemplateContent)
)

const (
CorednsContainerName = "coredns"
CorednsLabelKey = "k8s-app"
CorednsTemplateDep = "coredns-template.yaml"
)

func genVpcDNSDpName(name string) string {
return fmt.Sprintf("vpc-dns-%s", name)
}

func hostConfigFromReader() error {
file, err := os.Open("/etc/resolv.conf")
if err != nil {
klog.Error(err)
return err
}
defer func(file *os.File) {
if err := file.Close(); err != nil {
klog.Errorf("failed to close file, %s", err)
}
}(file)

scanner := bufio.NewScanner(file)
for scanner.Scan() {
if err := scanner.Err(); err != nil {
klog.Error(err)
return err
}
line := scanner.Text()
f := strings.Fields(line)
if len(f) < 1 {
continue
}
if f[0] == "nameserver" && len(f) > 1 {
name := f[1]
hostNameservers = append(hostNameservers, name)
}
}

return err
}

func (c *Controller) enqueueAddVpcDNS(obj interface{}) {
var key string
var err error
Expand Down Expand Up @@ -139,9 +104,9 @@ func (c *Controller) runDelVPCDNSWorker() {

func (c *Controller) handleAddOrUpdateVPCDNS(key string) error {
klog.V(3).Infof("handleAddOrUpdateVPCDNS %s", key)
if !enableCoredns {
if !enableCoreDNS {
time.Sleep(10 * time.Second)
if !enableCoredns {
if !enableCoreDNS {
return errors.New("failed to add or update vpc-dns, not enabled")
}
}
Expand Down Expand Up @@ -338,12 +303,7 @@ func (c *Controller) createOrUpdateVpcDNSSlr(vpcDNS *kubeovnv1.VpcDns) error {
}

func (c *Controller) genVpcDNSDeployment(vpcDNS *kubeovnv1.VpcDns, oldDeploy *v1.Deployment) (*v1.Deployment, error) {
if _, err := os.Stat(CorednsTemplateDep); errors.Is(err, os.ErrNotExist) {
klog.Errorf("failed to get coredns template file %q: %v", CorednsTemplateDep, err)
return nil, err
}

tmp, err := template.ParseFiles(CorednsTemplateDep)
tmp, err := template.ParseGlob(corednsTemplateContent)
if err != nil {
klog.Errorf("failed to parse coredns template file, %v", err)
return nil, err
Expand Down Expand Up @@ -532,12 +492,6 @@ func (c *Controller) resyncVpcDNSConfig() {
klog.V(3).Infof("use the cluster default coredns image version, %s", corednsImage)
}

err = os.WriteFile(CorednsTemplateDep, corednsTemplateContent, 0o600)
if err != nil {
klog.Errorf("failed to write coredns template to file %q: %v", CorednsTemplateDep, err)
return
}

nadName = getValue("nad-name")
nadProvider = getValue("nad-provider")
corednsVip = getValue("coredns-vip")
Expand All @@ -554,7 +508,7 @@ func (c *Controller) resyncVpcDNSConfig() {
newEnableCoredns = raw
}

if enableCoredns && !newEnableCoredns {
if enableCoreDNS && !newEnableCoredns {
if err := c.cleanVpcDNS(); err != nil {
klog.Errorf("failed to clear all vpc-dns, %v", err)
return
Expand All @@ -565,7 +519,7 @@ func (c *Controller) resyncVpcDNSConfig() {
return
}
}
enableCoredns = newEnableCoredns
enableCoreDNS = newEnableCoredns
}

func (c *Controller) getDefaultCoreDNSImage() (string, error) {
Expand All @@ -586,11 +540,6 @@ func (c *Controller) getDefaultCoreDNSImage() (string, error) {
}

func (c *Controller) initVpcDNSConfig() error {
if err := hostConfigFromReader(); err != nil {
klog.Errorf("failed to get get host nameserver, %v", err)
return err
}

c.resyncVpcDNSConfig()
return nil
}
Expand Down

0 comments on commit c78c4a9

Please sign in to comment.