gxthrj commented on a change in pull request #680: URL: https://github.com/apache/apisix-ingress-controller/pull/680#discussion_r710613079
########## File path: pkg/ingress/compare.go ########## @@ -0,0 +1,271 @@ +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package ingress + +import ( + "context" + "sync" + "time" + + "C" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + apisix "github.com/apache/apisix-ingress-controller/pkg/types/apisix/v1" +) + +// CompareResources use to compare the object IDs in resources and APISIX +// Find out the rest of objects in APISIX +// AND remove them. +func (c *Controller) CompareResources() { + var ( + routeMapK8S = new(sync.Map) + streamRouteMapK8S = new(sync.Map) + upstreamMapK8S = new(sync.Map) + sslMapK8S = new(sync.Map) + consumerMapK8S = new(sync.Map) + + routeMapA6 = new(sync.Map) + streamRouteMapA6 = new(sync.Map) + upstreamMapA6 = new(sync.Map) + sslMapA6 = new(sync.Map) + consumerMapA6 = new(sync.Map) + ) + // todo if watchingNamespace == nil + if c.watchingNamespace == nil { + opts := v1.ListOptions{} + // list all apisixroute resources in all namespaces + nsList, err := c.kubeClient.Client.CoreV1().Namespaces().List(context.TODO(), opts) + if err != nil { + panic(err) + } else { + wns := make(map[string]struct{}, len(nsList.Items)) + for _, v := range nsList.Items { + wns[v.Name] = struct{}{} + } + c.watchingNamespace = wns + } + } + for ns := range c.watchingNamespace { + // ApisixRoute + opts := v1.ListOptions{} + retRoutes, err := c.kubeClient.APISIXClient.ApisixV2beta1().ApisixRoutes(ns).List(context.TODO(), opts) + if err != nil { + panic(err) + } else { + for _, r := range retRoutes.Items { + tc, err := c.translator.TranslateRouteV2beta1NotStrictly(&r) + if err != nil { + panic(err) + } else { + // routes + for _, route := range tc.Routes { + routeMapK8S.Store(route.ID, route.ID) + } + // streamRoutes + for _, stRoute := range tc.StreamRoutes { + streamRouteMapK8S.Store(stRoute.ID, stRoute.ID) + } + // upstreams + for _, upstream := range tc.Upstreams { + upstreamMapK8S.Store(upstream.ID, upstream.ID) + } + // ssl + for _, ssl := range tc.SSL { + sslMapK8S.Store(ssl.ID, ssl.ID) + } + } + } + } + // todo ApisixUpstream + // ApisixUpstream should be synced with ApisixRoute resource + + // ApisixSSL + retSSL, err := c.kubeClient.APISIXClient.ApisixV1().ApisixTlses(ns).List(context.TODO(), opts) + if err != nil { + panic(err) + } else { + for _, s := range retSSL.Items { + ssl, err := c.translator.TranslateSSL(&s) + if err != nil { + panic(err) + } else { + sslMapK8S.Store(ssl.ID, ssl.ID) + } + } + } + // ApisixConsumer + retConsumer, err := c.kubeClient.APISIXClient.ApisixV2alpha1().ApisixConsumers(ns).List(context.TODO(), opts) + if err != nil { + panic(err) + } else { + for _, con := range retConsumer.Items { + consumer, err := c.translator.TranslateApisixConsumer(&con) + if err != nil { + panic(err) + } else { + consumerMapK8S.Store(consumer.Username, consumer.Username) + } + } + } + } + + // 2.get all cache routes + c.listRouteCache(routeMapA6) Review comment: That is because the cache has been verified before. cc https://github.com/apache/apisix-ingress-controller/blob/master/pkg/ingress/controller.go#L389 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
