mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Merge pull request #21935 from janetkuo/nil-pointer
Fix the nil pointer dereference when counting RS replicas
This commit is contained in:
commit
be6515ca90
@ -334,8 +334,10 @@ func SetFromReplicaSetTemplate(deployment *extensions.Deployment, template api.P
|
|||||||
func GetReplicaCountForReplicaSets(replicaSets []*extensions.ReplicaSet) int {
|
func GetReplicaCountForReplicaSets(replicaSets []*extensions.ReplicaSet) int {
|
||||||
totalReplicaCount := 0
|
totalReplicaCount := 0
|
||||||
for _, rs := range replicaSets {
|
for _, rs := range replicaSets {
|
||||||
|
if rs != nil {
|
||||||
totalReplicaCount += rs.Spec.Replicas
|
totalReplicaCount += rs.Spec.Replicas
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return totalReplicaCount
|
return totalReplicaCount
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,8 +345,10 @@ func GetReplicaCountForReplicaSets(replicaSets []*extensions.ReplicaSet) int {
|
|||||||
func GetActualReplicaCountForReplicaSets(replicaSets []*extensions.ReplicaSet) int {
|
func GetActualReplicaCountForReplicaSets(replicaSets []*extensions.ReplicaSet) int {
|
||||||
totalReplicaCount := 0
|
totalReplicaCount := 0
|
||||||
for _, rs := range replicaSets {
|
for _, rs := range replicaSets {
|
||||||
|
if rs != nil {
|
||||||
totalReplicaCount += rs.Status.Replicas
|
totalReplicaCount += rs.Status.Replicas
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return totalReplicaCount
|
return totalReplicaCount
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,6 +392,7 @@ func IsPodAvailable(pod *api.Pod, minReadySeconds int) bool {
|
|||||||
func GetPodsForReplicaSets(c clientset.Interface, replicaSets []*extensions.ReplicaSet) ([]api.Pod, error) {
|
func GetPodsForReplicaSets(c clientset.Interface, replicaSets []*extensions.ReplicaSet) ([]api.Pod, error) {
|
||||||
allPods := map[string]api.Pod{}
|
allPods := map[string]api.Pod{}
|
||||||
for _, rs := range replicaSets {
|
for _, rs := range replicaSets {
|
||||||
|
if rs != nil {
|
||||||
selector, err := unversioned.LabelSelectorAsSelector(rs.Spec.Selector)
|
selector, err := unversioned.LabelSelectorAsSelector(rs.Spec.Selector)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("invalid label selector: %v", err)
|
return nil, fmt.Errorf("invalid label selector: %v", err)
|
||||||
@ -401,6 +406,7 @@ func GetPodsForReplicaSets(c clientset.Interface, replicaSets []*extensions.Repl
|
|||||||
allPods[pod.Name] = pod
|
allPods[pod.Name] = pod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
requiredPods := []api.Pod{}
|
requiredPods := []api.Pod{}
|
||||||
for _, pod := range allPods {
|
for _, pod := range allPods {
|
||||||
requiredPods = append(requiredPods, pod)
|
requiredPods = append(requiredPods, pod)
|
||||||
|
Loading…
Reference in New Issue
Block a user