• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

noironetworks / aci-containers / 9880

13 Sep 2024 07:20AM UTC coverage: 69.912% (+0.02%) from 69.89%
9880

Pull #1396

travis-pro

web-flow
Merge c8926ac9f into 47ac39ec3
Pull Request #1396: Do not use cachedEpgDns to filter out fvRsDomAtt

0 of 10 new or added lines in 1 file covered. (0.0%)

3 existing lines in 2 files now uncovered.

13098 of 18735 relevant lines covered (69.91%)

0.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

7.26
/pkg/controller/proactiveconf.go
1
// Copyright 2019 Cisco Systems, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRATIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
// Handlers for ProactiveConf CR updates.
16

17
package controller
18

19
import (
20
        "context"
21
        "fmt"
22
        "strings"
23

24
        "github.com/noironetworks/aci-containers/pkg/apicapi"
25
        pcv1 "github.com/noironetworks/aci-containers/pkg/proactiveconf/apis/aci.pc/v1"
26
        proactiveconfclientset "github.com/noironetworks/aci-containers/pkg/proactiveconf/clientset/versioned"
27

28
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29
        "k8s.io/apimachinery/pkg/runtime"
30
        "k8s.io/apimachinery/pkg/watch"
31
        "k8s.io/client-go/tools/cache"
32
        "k8s.io/kubernetes/pkg/controller"
33
)
34

35
const (
36
        proactiveConfCRDName = "proactiveconfs.aci.pc"
37
)
38

39
func proactiveConfInit(cont *AciController, stopCh <-chan struct{}) {
×
40
        cont.log.Debug("Initializing proactiveConfClient")
×
41
        restconfig := cont.env.RESTConfig()
×
42
        proactiveConfClient, err := proactiveconfclientset.NewForConfig(restconfig)
×
43
        if err != nil {
×
44
                cont.log.Errorf("Failed to intialize proactiveConfClient")
×
45
                return
×
46
        }
×
47

48
        cont.initProactiveConfInformerFromClient(proactiveConfClient)
×
49
        go cont.proactiveConfInformer.Run(stopCh)
×
50
        cache.WaitForCacheSync(stopCh, cont.proactiveConfInformer.HasSynced)
×
51
}
52

53
func (cont *AciController) initProactiveConfInformerFromClient(
54
        proactiveConfClient *proactiveconfclientset.Clientset) {
×
55
        cont.initProactiveConfInformerBase(
×
56
                &cache.ListWatch{
×
57
                        ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
×
58
                                return proactiveConfClient.AciV1().ProactiveConfs().List(context.TODO(), options)
×
59
                        },
×
60
                        WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
×
61
                                return proactiveConfClient.AciV1().ProactiveConfs().Watch(context.TODO(), options)
×
62
                        },
×
63
                })
64
}
65

66
func (cont *AciController) initProactiveConfInformerBase(listWatch *cache.ListWatch) {
1✔
67
        cont.proactiveConfInformer = cache.NewSharedIndexInformer(
1✔
68
                listWatch,
1✔
69
                &pcv1.ProactiveConf{},
1✔
70
                controller.NoResyncPeriodFunc(),
1✔
71
                cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
1✔
72
        )
1✔
73
        cont.proactiveConfInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
1✔
74
                AddFunc: func(obj interface{}) {
1✔
75
                        cont.proactiveConfAdded(obj)
×
76
                },
×
77
                UpdateFunc: func(oldobj interface{}, newobj interface{}) {
×
78
                        cont.proactiveConfUpdate(oldobj, newobj)
×
79
                },
×
80
                DeleteFunc: func(obj interface{}) {
×
81
                        cont.proactiveConfDelete(obj)
×
82
                },
×
83
        })
84
}
85

86
func (cont *AciController) proactiveConfAdded(obj interface{}) {
×
87
        policy := obj.(*pcv1.ProactiveConf)
×
88
        cont.log.Infof("ProactiveConf added: %s", policy.Name)
×
89
        cont.updateProactiveConf(policy)
×
90
}
×
91

92
func (cont *AciController) proactiveConfUpdate(oldobj interface{}, newobj interface{}) {
×
93
        oldpolicy := oldobj.(*pcv1.ProactiveConf)
×
94
        newpolicy := newobj.(*pcv1.ProactiveConf)
×
95
        cont.log.Infof("ProactiveConf updated: %s", newpolicy.Name)
×
96
        if oldpolicy.Spec.VmmEpgDeploymentImmediacy == newpolicy.Spec.VmmEpgDeploymentImmediacy {
×
97
                cont.log.Infof("ProactiveConf update: No change in VmmEpgDeploymentImmediacy")
×
98
                return
×
99
        }
×
100
        cont.updateProactiveConf(newpolicy)
×
101
}
102

103
func (cont *AciController) proactiveConfDelete(obj interface{}) {
×
104
        cont.indexMutex.Lock()
×
105
        defer cont.indexMutex.Unlock()
×
106
        policy := obj.(*pcv1.ProactiveConf)
×
107
        cont.log.Infof("ProactiveConf deleted: %s", policy.Name)
×
108
        fvRsDomAttSlice := cont.getfvRsDomAtt()
×
109
        cont.deleteProactiveConf(fvRsDomAttSlice)
×
110
}
×
111

112
func (cont *AciController) filterfvRsDomAtt(imdata []apicapi.ApicObject) []apicapi.ApicObject {
×
113
        systemDnsToFilter := []string{
×
NEW
114
                fmt.Sprintf("uni/tn-%s/ap-aci-containers-%s/epg-aci-containers-system", cont.config.AciPolicyTenant, cont.config.AciPrefix),
×
NEW
115
                fmt.Sprintf("uni/tn-%s/ap-aci-containers-%s/epg-aci-containers-istio", cont.config.AciPolicyTenant, cont.config.AciPrefix),
×
NEW
116
                fmt.Sprintf("uni/tn-%s/ap-aci-containers-%s/epg-aci-containers-nodes", cont.config.AciPolicyTenant, cont.config.AciPrefix),
×
117
        }
×
118

×
NEW
119
        vmmDomPDn := fmt.Sprintf("uni/vmmp-%s/dom-%s", cont.config.AciVmmDomainType, cont.config.AciVmmDomain)
×
120

×
121
        var fvRsDomAttSlice []apicapi.ApicObject
×
122
        for _, fvRsDomAtt := range imdata {
×
123
                dn := fvRsDomAtt.GetAttr("dn").(string)
×
124

×
125
                rsdomAttIndex := strings.LastIndex(dn, "/rsdomAtt-")
×
126
                if rsdomAttIndex == -1 {
×
127
                        continue
×
128
                }
129

NEW
130
                skipEpg := false
×
NEW
131
                for _, epgDn := range systemDnsToFilter {
×
NEW
132
                        if strings.HasPrefix(dn, epgDn) {
×
NEW
133
                                skipEpg = true
×
NEW
134
                                break
×
135
                        }
136
                }
NEW
137
                if skipEpg {
×
UNCOV
138
                        continue
×
139
                }
140

141
                rsdomAttDn := dn[rsdomAttIndex+len("/rsdomAtt-"):]
×
142
                rsdomAttDn = strings.Trim(rsdomAttDn, "[]")
×
143
                if rsdomAttDn == vmmDomPDn {
×
144
                        fvRsDomAttSlice = append(fvRsDomAttSlice, fvRsDomAtt)
×
145
                }
×
146
        }
147

148
        return fvRsDomAttSlice
×
149
}
150

151
func (cont *AciController) getfvRsDomAtt() []apicapi.ApicObject {
×
152
        uri := fmt.Sprintf("/api/node/class/fvRsDomAtt.json?query-target-filter=and(wcard(fvRsDomAtt.dn,\"%s\"))", cont.config.AciPolicyTenant)
×
153
        resp, err := cont.apicConn.GetApicResponse(uri)
×
154
        if err != nil {
×
155
                cont.log.Errorf("Failed to get response from APIC: %v", err)
×
156
                return nil
×
157
        }
×
158
        return cont.filterfvRsDomAtt(resp.Imdata)
×
159
}
160

161
func (cont *AciController) postfvRsDomAtt(fvRsDomAttSlice []apicapi.ApicObject) {
×
162
        uri := fmt.Sprintf("/api/node/mo/uni/tn-%s.json", cont.config.AciPolicyTenant)
×
163
        err := cont.apicConn.PostApicObjects(uri, fvRsDomAttSlice)
×
164
        if err != nil {
×
165
                cont.log.Errorf("Failed to update the fvRsDomAtt: %v", err)
×
166
        }
×
167
}
168

169
func (cont *AciController) updateFvRsDomAttImmediacy(fvRsDomAttSlice []apicapi.ApicObject, instrImedcy, resImedcy string) {
×
170
        for _, fvRsDomAtt := range fvRsDomAttSlice {
×
171
                dn := fvRsDomAtt.GetAttr("dn").(string)
×
172
                fvRsDomAttNew := apicapi.EmptyApicObject("fvRsDomAtt", dn)
×
173
                fvRsDomAttNew.SetAttr("instrImedcy", instrImedcy)
×
174
                fvRsDomAttNew.SetAttr("resImedcy", resImedcy)
×
175
                cont.postfvRsDomAtt([]apicapi.ApicObject{fvRsDomAttNew})
×
176
        }
×
177
}
178

179
func (cont *AciController) updateProactiveConf(policy *pcv1.ProactiveConf) {
×
180
        cont.indexMutex.Lock()
×
181
        defer cont.indexMutex.Unlock()
×
182
        vmmEpgDeploymentImmediacy := policy.Spec.VmmEpgDeploymentImmediacy
×
183
        fvRsDomAttSlice := cont.getfvRsDomAtt()
×
184

×
185
        if vmmEpgDeploymentImmediacy == pcv1.VmmEpgDeploymentImmediacyTypeImmediate {
×
186
                cont.updateFvRsDomAttImmediacy(fvRsDomAttSlice, "immediate", "pre-provision")
×
187
        } else {
×
188
                cont.deleteProactiveConf(fvRsDomAttSlice)
×
189
        }
×
190
}
191

192
func (cont *AciController) deleteProactiveConf(fvRsDomAttSlice []apicapi.ApicObject) {
×
193
        cont.updateFvRsDomAttImmediacy(fvRsDomAttSlice, "lazy", "lazy")
×
194
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc