Skip to content

Commit

Permalink
Fixup a few NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCao committed Aug 20, 2024
1 parent dcd847f commit 009e5b3
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions internal/service/controller_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,17 @@ func (s *ControllerService) RequestLease(
return nil, err
}

var matchLabels map[string]string
var matchExpressions []metav1.LabelSelectorRequirement
for _, exp := range req.Selector.MatchExpressions {
matchExpressions = append(matchExpressions, metav1.LabelSelectorRequirement{
Key: exp.Key,
Operator: metav1.LabelSelectorOperator(exp.Operator),
Values: exp.Values,
})
if req.Selector != nil {
matchLabels = req.Selector.MatchLabels
for _, exp := range req.Selector.MatchExpressions {
matchExpressions = append(matchExpressions, metav1.LabelSelectorRequirement{
Key: exp.Key,
Operator: metav1.LabelSelectorOperator(exp.Operator),
Values: exp.Values,
})
}
}

var lease jumpstarterdevv1alpha1.Lease = jumpstarterdevv1alpha1.Lease{
Expand All @@ -394,7 +398,7 @@ func (s *ControllerService) RequestLease(
},
Duration: metav1.Duration{Duration: req.Duration.AsDuration()},
Selector: metav1.LabelSelector{
MatchLabels: req.Selector.MatchLabels,
MatchLabels: matchLabels,
MatchExpressions: matchExpressions,
},
},
Expand Down

0 comments on commit 009e5b3

Please sign in to comment.