Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-562 | Added code changes to update pod scheduling error message… #566

Merged
merged 3 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,8 @@ spec:
type: boolean
configErrors:
type: boolean
membersNotScheduled:
type: boolean
generationUID:
type: string
lastConnectionHash:
Expand Down Expand Up @@ -602,6 +604,8 @@ spec:
type: string
startScriptStderrMessage:
type: string
schedulingErrorMessage:
type: string
pendingNotifyCmds:
type: array
items:
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/kubedirector/v1beta1/kubedirectorcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ type StateRollup struct {
MembersWaiting bool `json:"membersWaiting"`
MembersRestarting bool `json:"membersRestarting"`
ConfigErrors bool `json:"configErrors"`
MembersNotScheduled bool `json:"membersNotScheduled"`
}

// ClusterStorage defines the persistent storage size/type, if any, to be used
Expand Down Expand Up @@ -234,6 +235,7 @@ type MemberStateDetail struct {
LastConnectionVersion *int64 `json:"lastConnectionVersion,omitempty"`
StartScriptOutMsg string `json:"startScriptStdoutMessage,omitempty"`
StartScriptErrMsg string `json:"startScriptStderrMessage,omitempty"`
SchedulingErrorMessage *string `json:"schedulingErrorMessage,omitempty"`
}

// NotificationDesc contains the info necessary to perform a notify command.
Expand Down
8 changes: 8 additions & 0 deletions pkg/controller/kubedirectorcluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@ func checkContainerStates(
for j := 0; j < numMemberStatuses; j++ {
memberStatus := &(roleStatus.Members[j])
containerID := ""
// clear SchedulingErrorMessage in MemberStateDetail
memberStatus.StateDetail.SchedulingErrorMessage = nil
if memberStatus.Pod != "" {
memberStatus.StateDetail.LastKnownContainerState = containerMissing
pod, podErr := observer.GetPod(cr.Namespace, memberStatus.Pod)
Expand Down Expand Up @@ -579,6 +581,8 @@ func checkContainerStates(
}
}
}
// Set pod blocking message in MemberStateDetail if LastKnownContainerState is containerMissing
updateSchedulingErrorMessage(pod, memberStatus)
}
}
}
Expand All @@ -596,6 +600,7 @@ func updateStateRollup(
cr.Status.MemberStateRollup.MembersWaiting = false
cr.Status.MemberStateRollup.MembersRestarting = false
cr.Status.MemberStateRollup.ConfigErrors = false
cr.Status.MemberStateRollup.MembersNotScheduled = false

checkMemberDown := func(memberStatus kdv1.MemberStatus) {
if (memberStatus.StateDetail.LastKnownContainerState == containerTerminated) ||
Expand All @@ -619,6 +624,9 @@ func updateStateRollup(
// Count missing container as waiting, at this point.
if memberStatus.StateDetail.LastKnownContainerState == containerMissing {
cr.Status.MemberStateRollup.MembersWaiting = true
if memberStatus.StateDetail.SchedulingErrorMessage != nil {
cr.Status.MemberStateRollup.MembersNotScheduled = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the block of stuff at the beginning of this function we must also set MembersNotScheduled to false initially.

}
}
case memberCreating:
checkMemberDown(memberStatus)
Expand Down
37 changes: 37 additions & 0 deletions pkg/controller/kubedirectorcluster/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2022 Hewlett Packard Enterprise Development LP

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package kubedirectorcluster

import (
kdv1 "github.com/bluek8s/kubedirector/pkg/apis/kubedirector/v1beta1"
corev1 "k8s.io/api/core/v1"
)

// updateSchedulingErrorMessage updates MemberStateDetails with SchedulingErrorMessage
func updateSchedulingErrorMessage(
pod *corev1.Pod,
memberStatus *kdv1.MemberStatus,
) {

if memberStatus.StateDetail.LastKnownContainerState == containerMissing {
for _, condition := range pod.Status.Conditions {
if condition.Type == corev1.PodScheduled {
if condition.Reason == corev1.PodReasonUnschedulable {
memberStatus.StateDetail.SchedulingErrorMessage = &condition.Message
}
}
}
}
}