Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Commit

Permalink
Cleanup and refactoring based on review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Milan Klanjsek <[email protected]>
  • Loading branch information
mklanjsek committed May 27, 2021
1 parent 71e10a0 commit bfc1189
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 40 deletions.
33 changes: 17 additions & 16 deletions internal/objectstatus/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ func daemonSet(_ context.Context, object runtime.Object, _ store.Store, _ link.I

var properties []component.Property

if selector := ds.Spec.Selector; selector != nil {
properties = append(properties, component.Property{Label: "Selectors", Value: getSelectors(selector)})
}
properties = append(properties, component.Property{Label: "Selectors", Value: GetSelectors(ds.Spec.Selector)})

if nodeSelector := ds.Spec.Template.Spec.NodeSelector; nodeSelector != nil {
properties = append(properties, component.Property{Label: "Node Selectors", Value: getSelectorMap(nodeSelector)})
Expand Down Expand Up @@ -66,21 +64,24 @@ func daemonSet(_ context.Context, object runtime.Object, _ store.Store, _ link.I
}
}

func getSelectors(selector *metav1.LabelSelector) component.Component {
selectorComponent := component.NewSelectors(nil)
if selector == nil {
func GetSelectors(selector *metav1.LabelSelector) component.Component {
if selector != nil {
selectorComponent := component.NewSelectors(nil)
if selector == nil {
return selectorComponent
}

for k, v := range selector.MatchLabels {
selectorComponent.Add(component.NewLabelSelector(k, v))
}

for _, e := range selector.MatchExpressions {
es := component.NewExpressionSelector(e.Key, component.Operator(e.Operator), e.Values)
selectorComponent.Add(es)
}
return selectorComponent
}

for k, v := range selector.MatchLabels {
selectorComponent.Add(component.NewLabelSelector(k, v))
}

for _, e := range selector.MatchExpressions {
es := component.NewExpressionSelector(e.Key, component.Operator(e.Operator), e.Values)
selectorComponent.Add(es)
}
return selectorComponent
return component.NewText("None")
}

func getSelectorMap(selector map[string]string) *component.Selectors {
Expand Down
23 changes: 1 addition & 22 deletions internal/objectstatus/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func deploymentAppsV1(_ context.Context, object runtime.Object, _ store.Store, _

status := deployment.Status
properties := []component.Property{{Label: "Deployment Strategy", Value: component.NewText(string(deployment.Spec.Strategy.Type))},
{Label: "Selectors", Value: getSelector(deployment)}}
{Label: "Selectors", Value: GetSelectors(deployment.Spec.Selector)}}

switch {
case status.Replicas == status.UnavailableReplicas:
Expand All @@ -61,24 +61,3 @@ func deploymentAppsV1(_ context.Context, object runtime.Object, _ store.Store, _
}, nil
}
}

func getSelector(deployment *appsv1.Deployment) component.Component {
if selector := deployment.Spec.Selector; selector != nil {
var selectors []component.Selector

for _, lsr := range selector.MatchExpressions {
o, _ := component.MatchOperator(string(lsr.Operator))

es := component.NewExpressionSelector(lsr.Key, o, lsr.Values)
selectors = append(selectors, es)
}

for k, v := range selector.MatchLabels {
ls := component.NewLabelSelector(k, v)
selectors = append(selectors, ls)
}

return component.NewSelectors(selectors)
}
return component.NewText("None")
}
4 changes: 2 additions & 2 deletions internal/objectstatus/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func pod(ctx context.Context, object runtime.Object, o store.Store, link link.In

if nodeName := pod.Spec.NodeName; nodeName != "" {
nodeLink, _ := link.ForGVK("", "v1", "Node", pod.Spec.NodeName, pod.Spec.NodeName)
status.Properties = append(status.Properties, component.Property{Label: "Node", Value: nodeLink})
status.AddProperty("Node", nodeLink)
}

ownerReference := metav1.GetControllerOf(pod)
Expand All @@ -71,7 +71,7 @@ func pod(ctx context.Context, object runtime.Object, o store.Store, link link.In
ownerReference.Name,
)
if err == nil {
status.Properties = append(status.Properties, component.Property{Label: "Controlled By", Value: controlledBy})
status.AddProperty("Controlled By", controlledBy)
}
}
}
Expand Down

0 comments on commit bfc1189

Please sign in to comment.