From c78c4a9781bfe6baafa4787c5bb3a1966963c8f0 Mon Sep 17 00:00:00 2001 From: zhangzujian Date: Wed, 24 Jul 2024 12:07:56 +0000 Subject: [PATCH] vpc dns: remove unused variable Signed-off-by: zhangzujian --- pkg/controller/vpc_dns.go | 81 ++++++++------------------------------- 1 file changed, 15 insertions(+), 66 deletions(-) diff --git a/pkg/controller/vpc_dns.go b/pkg/controller/vpc_dns.go index 0925a6755b93..16f2abe92f62 100644 --- a/pkg/controller/vpc_dns.go +++ b/pkg/controller/vpc_dns.go @@ -1,7 +1,6 @@ package controller import ( - "bufio" "bytes" "context" "encoding/json" @@ -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 @@ -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") } } @@ -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 @@ -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") @@ -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 @@ -565,7 +519,7 @@ func (c *Controller) resyncVpcDNSConfig() { return } } - enableCoredns = newEnableCoredns + enableCoreDNS = newEnableCoredns } func (c *Controller) getDefaultCoreDNSImage() (string, error) { @@ -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 }