Skip to content

Commit 50a9620

Browse files
committed
add log level 2
Signed-off-by: Swati Gupta <[email protected]>
1 parent 7fe7ff2 commit 50a9620

File tree

1 file changed

+21
-35
lines changed

1 file changed

+21
-35
lines changed

cmd/compute-domain-controller/computedomain.go

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func NewComputeDomainManager(config *ManagerConfig) *ComputeDomainManager {
6464
factory := nvinformers.NewSharedInformerFactory(config.clientsets.Nvidia, informerResyncPeriod)
6565
informer := factory.Resource().V1beta1().ComputeDomains().Informer()
6666

67-
klog.Infof("Creating new ComputeDomainManager with config %+v", config)
67+
klog.Infof("Creating new ComputeDomainManager for %s/%s", config.driverName, config.driverNamespace)
6868
m := &ComputeDomainManager{
6969
config: config,
7070
factory: factory,
@@ -149,7 +149,7 @@ func (m *ComputeDomainManager) Get(uid string) (*nvapi.ComputeDomain, error) {
149149
return nil, fmt.Errorf("error retrieving ComputeDomain by UID: %w", err)
150150
}
151151
if len(cds) == 0 {
152-
klog.Infof("No ComputeDomain found with UID: %s", uid)
152+
klog.V(2).Infof("No ComputeDomain found with UID: %s", uid)
153153
return nil, nil
154154
}
155155
if len(cds) != 1 {
@@ -169,7 +169,7 @@ func (m *ComputeDomainManager) RemoveFinalizer(ctx context.Context, uid string)
169169
return fmt.Errorf("error retrieving ComputeDomain: %w", err)
170170
}
171171
if cd == nil {
172-
klog.Infof("ComputeDomain with UID %s not found, nothing to do", uid)
172+
klog.V(2).Infof("ComputeDomain with UID %s not found, nothing to do", uid)
173173
return nil
174174
}
175175

@@ -185,16 +185,31 @@ func (m *ComputeDomainManager) RemoveFinalizer(ctx context.Context, uid string)
185185
}
186186
}
187187
if len(cd.Finalizers) == len(newCD.Finalizers) {
188-
klog.Infof("Finalizer not found on ComputeDomain %s/%s, nothing to do", cd.Namespace, cd.Name)
188+
klog.V(2).Infof("Finalizer not found on ComputeDomain %s/%s, nothing to do", cd.Namespace, cd.Name)
189189
return nil
190190
}
191191

192192
if _, err = m.config.clientsets.Nvidia.ResourceV1beta1().ComputeDomains(cd.Namespace).Update(ctx, newCD, metav1.UpdateOptions{}); err != nil {
193193
return fmt.Errorf("error updating ComputeDomain: %w", err)
194194
}
195+
195196
return nil
196197
}
197198

199+
// logNodesWithComputeDomainLabel logs nodes that have a ComputeDomain label and returns their names
200+
func (m *ComputeDomainManager) logNodesWithComputeDomainLabel(nodes *corev1.NodeList, cdUID string) []string {
201+
if len(nodes.Items) == 0 {
202+
klog.Infof("No nodes found with label for ComputeDomain with UID %s", cdUID)
203+
return nil
204+
}
205+
206+
nodeNames := []string{}
207+
for _, node := range nodes.Items {
208+
nodeNames = append(nodeNames, node.Name)
209+
}
210+
return nodeNames
211+
}
212+
198213
// AssertWorkloadsCompletes ensures that all workloads asssociated with a ComputeDomain have completed.
199214
//
200215
// TODO: We should probably also check to ensure that all ResourceClaims
@@ -219,38 +234,9 @@ func (m *ComputeDomainManager) AssertWorkloadsCompleted(ctx context.Context, cdU
219234
}
220235

221236
if len(nodes.Items) != 0 {
222-
// show nodes with labels
223-
nodeNames := []string{}
224-
for _, node := range nodes.Items {
225-
nodeNames = append(nodeNames, node.Name)
226-
}
227-
klog.Errorf("Found %d nodes with label for ComputeDomain with UID %s: %v", len(nodes.Items), cdUID, nodeNames)
228-
return fmt.Errorf("nodes exist with label for ComputeDomain %s", cdUID)
237+
nodeNames := logNodesWithComputeDomainLabel(nodes, cdUID)
238+
return fmt.Errorf("nodes %v with label for ComputeDomain %s", nodeNames, cdUID)
229239
}
230-
231-
// check if all resource claims for workloads are gone
232-
cd, err := m.Get(cdUID)
233-
if err != nil {
234-
return fmt.Errorf("error retrieving ComputeDomain: %w", err)
235-
}
236-
237-
resourceClaims, err := m.config.clientsets.Core.ResourceV1beta1().ResourceClaims(cd.Namespace).List(ctx, metav1.ListOptions{
238-
LabelSelector: metav1.FormatLabelSelector(labelSelector),
239-
})
240-
if err != nil {
241-
return fmt.Errorf("error retrieving ResourceClaims: %w", err)
242-
}
243-
244-
if len(resourceClaims.Items) != 0 {
245-
claimNames := []string{}
246-
for _, claim := range resourceClaims.Items {
247-
claimNames = append(claimNames, claim.Name)
248-
}
249-
klog.Errorf("Found %d ResourceClaims for ComputeDomain with UID %s: %v",
250-
len(resourceClaims.Items), cdUID, claimNames)
251-
return fmt.Errorf("ResourceClaims exist for ComputeDomain %s", cdUID)
252-
}
253-
254240
return nil
255241
}
256242

0 commit comments

Comments
 (0)