Unverified Commit d8d9589a authored by rithu leena john's avatar rithu leena john Committed by GitHub
Browse files

k8s: update pod proto to extract more status info (#1252)

parent 9c772fee
No related merge requests found
Showing with 1989 additions and 596 deletions
+1989 -596
......@@ -256,6 +256,32 @@ message Container {
State state = 3;
bool ready = 4;
int32 restart_count = 5;
// ref: https://pkg.go.dev/k8s.io/api/core/v1#ContainerState
oneof state_details {
StateWaiting state_waiting = 6;
StateRunning state_running = 7;
StateTerminated state_terminated = 8;
}
}
// ref: https://pkg.go.dev/k8s.io/api/core/v1#ContainerStateWaiting
message StateWaiting {
string reason = 1;
string message = 2;
}
// ref: https://pkg.go.dev/k8s.io/api/core/v1#ContainerStateRunning
message StateRunning {
google.protobuf.Timestamp start_time = 1;
}
// ref: https://pkg.go.dev/k8s.io/api/core/v1#ContainerStateTerminated
message StateTerminated {
string reason = 1;
string message = 2;
int32 exit_code = 3;
int32 signal = 4;
}
message PodCondition {
......@@ -315,6 +341,10 @@ message Pod {
// current service state of pod.
// https://pkg.go.dev/k8s.io/api/core/v1#PodCondition
repeated PodCondition pod_conditions = 12;
// one entry per init container.
// ref: https://pkg.go.dev/k8s.io/api/core/v1#PodStatus
repeated Container init_containers = 13;
}
message ListOptions {
......
This diff is collapsed.
......@@ -229,6 +229,46 @@ func (m *Container) Validate() error {
// no validation rules for RestartCount
switch m.StateDetails.(type) {
case *Container_StateWaiting:
if v, ok := interface{}(m.GetStateWaiting()).(interface{ Validate() error }); ok {
if err := v.Validate(); err != nil {
return ContainerValidationError{
field: "StateWaiting",
reason: "embedded message failed validation",
cause: err,
}
}
}
case *Container_StateRunning:
if v, ok := interface{}(m.GetStateRunning()).(interface{ Validate() error }); ok {
if err := v.Validate(); err != nil {
return ContainerValidationError{
field: "StateRunning",
reason: "embedded message failed validation",
cause: err,
}
}
}
case *Container_StateTerminated:
if v, ok := interface{}(m.GetStateTerminated()).(interface{ Validate() error }); ok {
if err := v.Validate(); err != nil {
return ContainerValidationError{
field: "StateTerminated",
reason: "embedded message failed validation",
cause: err,
}
}
}
}
return nil
}
......@@ -286,6 +326,223 @@ var _ interface {
ErrorName() string
} = ContainerValidationError{}
// Validate checks the field values on StateWaiting with the rules defined in
// the proto definition for this message. If any rules are violated, an error
// is returned.
func (m *StateWaiting) Validate() error {
if m == nil {
return nil
}
// no validation rules for Reason
// no validation rules for Message
return nil
}
// StateWaitingValidationError is the validation error returned by
// StateWaiting.Validate if the designated constraints aren't met.
type StateWaitingValidationError struct {
field string
reason string
cause error
key bool
}
// Field function returns field value.
func (e StateWaitingValidationError) Field() string { return e.field }
// Reason function returns reason value.
func (e StateWaitingValidationError) Reason() string { return e.reason }
// Cause function returns cause value.
func (e StateWaitingValidationError) Cause() error { return e.cause }
// Key function returns key value.
func (e StateWaitingValidationError) Key() bool { return e.key }
// ErrorName returns error name.
func (e StateWaitingValidationError) ErrorName() string { return "StateWaitingValidationError" }
// Error satisfies the builtin error interface
func (e StateWaitingValidationError) Error() string {
cause := ""
if e.cause != nil {
cause = fmt.Sprintf(" | caused by: %v", e.cause)
}
key := ""
if e.key {
key = "key for "
}
return fmt.Sprintf(
"invalid %sStateWaiting.%s: %s%s",
key,
e.field,
e.reason,
cause)
}
var _ error = StateWaitingValidationError{}
var _ interface {
Field() string
Reason() string
Key() bool
Cause() error
ErrorName() string
} = StateWaitingValidationError{}
// Validate checks the field values on StateRunning with the rules defined in
// the proto definition for this message. If any rules are violated, an error
// is returned.
func (m *StateRunning) Validate() error {
if m == nil {
return nil
}
if v, ok := interface{}(m.GetStartTime()).(interface{ Validate() error }); ok {
if err := v.Validate(); err != nil {
return StateRunningValidationError{
field: "StartTime",
reason: "embedded message failed validation",
cause: err,
}
}
}
return nil
}
// StateRunningValidationError is the validation error returned by
// StateRunning.Validate if the designated constraints aren't met.
type StateRunningValidationError struct {
field string
reason string
cause error
key bool
}
// Field function returns field value.
func (e StateRunningValidationError) Field() string { return e.field }
// Reason function returns reason value.
func (e StateRunningValidationError) Reason() string { return e.reason }
// Cause function returns cause value.
func (e StateRunningValidationError) Cause() error { return e.cause }
// Key function returns key value.
func (e StateRunningValidationError) Key() bool { return e.key }
// ErrorName returns error name.
func (e StateRunningValidationError) ErrorName() string { return "StateRunningValidationError" }
// Error satisfies the builtin error interface
func (e StateRunningValidationError) Error() string {
cause := ""
if e.cause != nil {
cause = fmt.Sprintf(" | caused by: %v", e.cause)
}
key := ""
if e.key {
key = "key for "
}
return fmt.Sprintf(
"invalid %sStateRunning.%s: %s%s",
key,
e.field,
e.reason,
cause)
}
var _ error = StateRunningValidationError{}
var _ interface {
Field() string
Reason() string
Key() bool
Cause() error
ErrorName() string
} = StateRunningValidationError{}
// Validate checks the field values on StateTerminated with the rules defined
// in the proto definition for this message. If any rules are violated, an
// error is returned.
func (m *StateTerminated) Validate() error {
if m == nil {
return nil
}
// no validation rules for Reason
// no validation rules for Message
// no validation rules for ExitCode
// no validation rules for Signal
return nil
}
// StateTerminatedValidationError is the validation error returned by
// StateTerminated.Validate if the designated constraints aren't met.
type StateTerminatedValidationError struct {
field string
reason string
cause error
key bool
}
// Field function returns field value.
func (e StateTerminatedValidationError) Field() string { return e.field }
// Reason function returns reason value.
func (e StateTerminatedValidationError) Reason() string { return e.reason }
// Cause function returns cause value.
func (e StateTerminatedValidationError) Cause() error { return e.cause }
// Key function returns key value.
func (e StateTerminatedValidationError) Key() bool { return e.key }
// ErrorName returns error name.
func (e StateTerminatedValidationError) ErrorName() string { return "StateTerminatedValidationError" }
// Error satisfies the builtin error interface
func (e StateTerminatedValidationError) Error() string {
cause := ""
if e.cause != nil {
cause = fmt.Sprintf(" | caused by: %v", e.cause)
}
key := ""
if e.key {
key = "key for "
}
return fmt.Sprintf(
"invalid %sStateTerminated.%s: %s%s",
key,
e.field,
e.reason,
cause)
}
var _ error = StateTerminatedValidationError{}
var _ interface {
Field() string
Reason() string
Key() bool
Cause() error
ErrorName() string
} = StateTerminatedValidationError{}
// Validate checks the field values on PodCondition with the rules defined in
// the proto definition for this message. If any rules are violated, an error
// is returned.
......@@ -420,6 +677,21 @@ func (m *Pod) Validate() error {
}
for idx, item := range m.GetInitContainers() {
_, _ = idx, item
if v, ok := interface{}(item).(interface{ Validate() error }); ok {
if err := v.Validate(); err != nil {
return PodValidationError{
field: fmt.Sprintf("InitContainers[%v]", idx),
reason: "embedded message failed validation",
cause: err,
}
}
}
}
return nil
}
......
......@@ -184,10 +184,11 @@ func podDescription(k8spod *corev1.Pod, cluster string) *k8sapiv1.Pod {
PodIp: k8spod.Status.PodIP,
State: protoForPodState(k8spod.Status.Phase),
//StartTime: launch,
Labels: k8spod.Labels,
Annotations: k8spod.Annotations,
StateReason: k8spod.Status.Reason,
PodConditions: makeConditions(k8spod.Status.Conditions),
Labels: k8spod.Labels,
Annotations: k8spod.Annotations,
StateReason: k8spod.Status.Reason,
PodConditions: makeConditions(k8spod.Status.Conditions),
InitContainers: makeContainers(k8spod.Status.InitContainerStatuses),
}
}
......@@ -213,6 +214,15 @@ func makeContainers(statuses []corev1.ContainerStatus) []*k8sapiv1.Container {
Ready: status.Ready,
RestartCount: status.RestartCount,
}
switch container.State {
case k8sapiv1.Container_TERMINATED:
container.StateDetails = protoForContainerStateTerminated(status.State.Terminated)
case k8sapiv1.Container_RUNNING:
container.StateDetails = protoForContainerStateRunning(status.State.Running)
case k8sapiv1.Container_WAITING:
container.StateDetails = protoForContainerStateWaiting(status.State.Waiting)
}
containers = append(containers, container)
}
return containers
......@@ -241,6 +251,35 @@ func protoForContainerState(state corev1.ContainerState) k8sapiv1.Container_Stat
}
}
func protoForContainerStateWaiting(state *corev1.ContainerStateWaiting) *k8sapiv1.Container_StateWaiting {
return &k8sapiv1.Container_StateWaiting{
StateWaiting: &k8sapiv1.StateWaiting{
Reason: state.Reason,
Message: state.Message,
},
}
}
func protoForContainerStateTerminated(state *corev1.ContainerStateTerminated) *k8sapiv1.Container_StateTerminated {
return &k8sapiv1.Container_StateTerminated{
StateTerminated: &k8sapiv1.StateTerminated{
Reason: state.Reason,
Message: state.Message,
ExitCode: state.ExitCode,
Signal: state.Signal,
},
}
}
func protoForContainerStateRunning(state *corev1.ContainerStateRunning) *k8sapiv1.Container_StateRunning {
return &k8sapiv1.Container_StateRunning{
StateRunning: &k8sapiv1.StateRunning{
// FE serialization currently does not support timestamp
//StartTime: state.StartedAt,
},
}
}
func protoForConditionType(conditionType corev1.PodConditionType) k8sapiv1.PodCondition_Type {
switch conditionType {
case corev1.ContainersReady:
......
......@@ -260,6 +260,11 @@ func TestPodDescription(t *testing.T) {
{Name: "container2"},
{Name: "container3"},
},
InitContainerStatuses: []corev1.ContainerStatus{
{Name: "initcontainer1"},
{Name: "initcontainer2"},
{Name: "initcontainer3"},
},
Reason: "Evicted",
Conditions: []corev1.PodCondition{
corev1.PodCondition{
......@@ -285,6 +290,11 @@ func TestPodDescription(t *testing.T) {
{Name: "container2"},
{Name: "container3"},
},
InitContainerStatuses: []corev1.ContainerStatus{
{Name: "initcontainer1"},
{Name: "initcontainer2"},
{Name: "initcontainer3"},
},
Reason: "Evicted",
Conditions: []corev1.PodCondition{
corev1.PodCondition{
......@@ -305,6 +315,7 @@ func TestPodDescription(t *testing.T) {
pod := podDescription(tt.pod, tt.inputClusterName)
assert.Equal(t, tt.expectedClusterName, pod.Cluster)
assert.Equal(t, tt.pod.Status.Reason, pod.StateReason)
assert.Equal(t, tt.pod.Status.InitContainerStatuses[0].Name, pod.InitContainers[0].Name)
assert.Equal(t, k8sv1.PodCondition_Type(1), pod.PodConditions[0].Type)
assert.Equal(t, k8sv1.PodCondition_Status(1), pod.PodConditions[0].Status)
})
......@@ -453,13 +464,19 @@ func TestMakeContainers(t *testing.T) {
Ready: false,
RestartCount: 0,
State: k8sv1.Container_RUNNING,
StateDetails: &k8sv1.Container_StateRunning{
StateRunning: &k8sv1.StateRunning{},
},
},
{
Name: "TheContainer",
Image: "foo",
Ready: true,
RestartCount: 5,
State: k8sv1.Container_RUNNING,
State: k8sv1.Container_WAITING,
StateDetails: &k8sv1.Container_StateWaiting{
StateWaiting: &k8sv1.StateWaiting{},
},
},
},
statuses: []corev1.ContainerStatus{
......@@ -478,7 +495,7 @@ func TestMakeContainers(t *testing.T) {
Ready: true,
RestartCount: 5,
State: corev1.ContainerState{
Running: &corev1.ContainerStateRunning{},
Waiting: &corev1.ContainerStateWaiting{},
},
},
},
......@@ -491,7 +508,10 @@ func TestMakeContainers(t *testing.T) {
Image: "giraffe",
Ready: true,
RestartCount: 1,
State: k8sv1.Container_RUNNING,
State: k8sv1.Container_TERMINATED,
StateDetails: &k8sv1.Container_StateTerminated{
StateTerminated: &k8sv1.StateTerminated{},
},
},
},
statuses: []corev1.ContainerStatus{
......@@ -501,7 +521,7 @@ func TestMakeContainers(t *testing.T) {
Ready: true,
RestartCount: 1,
State: corev1.ContainerState{
Running: &corev1.ContainerStateRunning{},
Terminated: &corev1.ContainerStateTerminated{},
},
},
},
......
......@@ -11045,6 +11045,15 @@ export namespace clutch {
 
/** Container restartCount */
restartCount?: (number|null);
/** Container stateWaiting */
stateWaiting?: (clutch.k8s.v1.IStateWaiting|null);
/** Container stateRunning */
stateRunning?: (clutch.k8s.v1.IStateRunning|null);
/** Container stateTerminated */
stateTerminated?: (clutch.k8s.v1.IStateTerminated|null);
}
 
/** Represents a Container. */
......@@ -11071,6 +11080,18 @@ export namespace clutch {
/** Container restartCount. */
public restartCount: number;
 
/** Container stateWaiting. */
public stateWaiting?: (clutch.k8s.v1.IStateWaiting|null);
/** Container stateRunning. */
public stateRunning?: (clutch.k8s.v1.IStateRunning|null);
/** Container stateTerminated. */
public stateTerminated?: (clutch.k8s.v1.IStateTerminated|null);
/** Container stateDetails. */
public stateDetails?: ("stateWaiting"|"stateRunning"|"stateTerminated");
/**
* Verifies a Container message.
* @param message Plain object to verify
......@@ -11112,6 +11133,174 @@ export namespace clutch {
}
}
 
/** Properties of a StateWaiting. */
interface IStateWaiting {
/** StateWaiting reason */
reason?: (string|null);
/** StateWaiting message */
message?: (string|null);
}
/** Represents a StateWaiting. */
class StateWaiting implements IStateWaiting {
/**
* Constructs a new StateWaiting.
* @param [properties] Properties to set
*/
constructor(properties?: clutch.k8s.v1.IStateWaiting);
/** StateWaiting reason. */
public reason: string;
/** StateWaiting message. */
public message: string;
/**
* Verifies a StateWaiting message.
* @param message Plain object to verify
* @returns `null` if valid, otherwise the reason why it is not
*/
public static verify(message: { [k: string]: any }): (string|null);
/**
* Creates a StateWaiting message from a plain object. Also converts values to their respective internal types.
* @param object Plain object
* @returns StateWaiting
*/
public static fromObject(object: { [k: string]: any }): clutch.k8s.v1.StateWaiting;
/**
* Creates a plain object from a StateWaiting message. Also converts values to other types if specified.
* @param message StateWaiting
* @param [options] Conversion options
* @returns Plain object
*/
public static toObject(message: clutch.k8s.v1.StateWaiting, options?: $protobuf.IConversionOptions): { [k: string]: any };
/**
* Converts this StateWaiting to JSON.
* @returns JSON object
*/
public toJSON(): { [k: string]: any };
}
/** Properties of a StateRunning. */
interface IStateRunning {
/** StateRunning startTime */
startTime?: (google.protobuf.ITimestamp|null);
}
/** Represents a StateRunning. */
class StateRunning implements IStateRunning {
/**
* Constructs a new StateRunning.
* @param [properties] Properties to set
*/
constructor(properties?: clutch.k8s.v1.IStateRunning);
/** StateRunning startTime. */
public startTime?: (google.protobuf.ITimestamp|null);
/**
* Verifies a StateRunning message.
* @param message Plain object to verify
* @returns `null` if valid, otherwise the reason why it is not
*/
public static verify(message: { [k: string]: any }): (string|null);
/**
* Creates a StateRunning message from a plain object. Also converts values to their respective internal types.
* @param object Plain object
* @returns StateRunning
*/
public static fromObject(object: { [k: string]: any }): clutch.k8s.v1.StateRunning;
/**
* Creates a plain object from a StateRunning message. Also converts values to other types if specified.
* @param message StateRunning
* @param [options] Conversion options
* @returns Plain object
*/
public static toObject(message: clutch.k8s.v1.StateRunning, options?: $protobuf.IConversionOptions): { [k: string]: any };
/**
* Converts this StateRunning to JSON.
* @returns JSON object
*/
public toJSON(): { [k: string]: any };
}
/** Properties of a StateTerminated. */
interface IStateTerminated {
/** StateTerminated reason */
reason?: (string|null);
/** StateTerminated message */
message?: (string|null);
/** StateTerminated exitCode */
exitCode?: (number|null);
/** StateTerminated signal */
signal?: (number|null);
}
/** Represents a StateTerminated. */
class StateTerminated implements IStateTerminated {
/**
* Constructs a new StateTerminated.
* @param [properties] Properties to set
*/
constructor(properties?: clutch.k8s.v1.IStateTerminated);
/** StateTerminated reason. */
public reason: string;
/** StateTerminated message. */
public message: string;
/** StateTerminated exitCode. */
public exitCode: number;
/** StateTerminated signal. */
public signal: number;
/**
* Verifies a StateTerminated message.
* @param message Plain object to verify
* @returns `null` if valid, otherwise the reason why it is not
*/
public static verify(message: { [k: string]: any }): (string|null);
/**
* Creates a StateTerminated message from a plain object. Also converts values to their respective internal types.
* @param object Plain object
* @returns StateTerminated
*/
public static fromObject(object: { [k: string]: any }): clutch.k8s.v1.StateTerminated;
/**
* Creates a plain object from a StateTerminated message. Also converts values to other types if specified.
* @param message StateTerminated
* @param [options] Conversion options
* @returns Plain object
*/
public static toObject(message: clutch.k8s.v1.StateTerminated, options?: $protobuf.IConversionOptions): { [k: string]: any };
/**
* Converts this StateTerminated to JSON.
* @returns JSON object
*/
public toJSON(): { [k: string]: any };
}
/** Properties of a PodCondition. */
interface IPodCondition {
 
......@@ -11224,6 +11413,9 @@ export namespace clutch {
 
/** Pod podConditions */
podConditions?: (clutch.k8s.v1.IPodCondition[]|null);
/** Pod initContainers */
initContainers?: (clutch.k8s.v1.IContainer[]|null);
}
 
/** Represents a Pod. */
......@@ -11271,6 +11463,9 @@ export namespace clutch {
/** Pod podConditions. */
public podConditions: clutch.k8s.v1.IPodCondition[];
 
/** Pod initContainers. */
public initContainers: clutch.k8s.v1.IContainer[];
/**
* Verifies a Pod message.
* @param message Plain object to verify
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment