Commit 5210f213 authored by SHAWNA MONERO's avatar SHAWNA MONERO
Browse files

adding in deployment status fields to proto

parent 0bcc7718
Showing with 2440 additions and 1115 deletions
+2440 -1115
......@@ -419,6 +419,38 @@ message Deployment {
map<string, string> labels = 4;
map<string, string> annotations = 5;
message DeploymentStatus {
uint32 replicas = 1;
uint32 updated_replicas = 2;
uint32 ready_replicas = 3;
uint32 available_replicas = 4;
uint32 unavailable_replicas = 5;
message Condition {
// This is mirroring upstream values here:
// https://pkg.go.dev/k8s.io/api/apps/v1#DeploymentConditionType
enum Type {
UNSPECIFIED = 0;
UNKNOWN = 1;
AVAILABLE = 2;
PROGRESSING = 3;
REPLICA_FAILURE = 4;
}
Type type = 1;
enum ConditionStatus {
CONDITION_UNSPECIFIED = 0;
CONDITION_TRUE = 1;
CONDITION_FALSE = 2;
CONDITION_UNKNOWN = 3;
}
ConditionStatus condition_status = 2;
string reason = 5;
string message = 6;
}
repeated Condition deployment_conditions = 6;
}
DeploymentStatus deployment_status = 6;
}
message DescribeDeploymentRequest {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -1429,6 +1429,16 @@ func (m *Deployment) Validate() error {
// no validation rules for Annotations
if v, ok := interface{}(m.GetDeploymentStatus()).(interface{ Validate() error }); ok {
if err := v.Validate(); err != nil {
return DeploymentValidationError{
field: "DeploymentStatus",
reason: "embedded message failed validation",
cause: err,
}
}
}
return nil
}
......@@ -6006,6 +6016,175 @@ var _ interface {
ErrorName() string
} = ResizeHPARequest_SizingValidationError{}
// Validate checks the field values on Deployment_DeploymentStatus with the
// rules defined in the proto definition for this message. If any rules are
// violated, an error is returned.
func (m *Deployment_DeploymentStatus) Validate() error {
if m == nil {
return nil
}
// no validation rules for Replicas
// no validation rules for UpdatedReplicas
// no validation rules for ReadyReplicas
// no validation rules for AvailableReplicas
// no validation rules for UnavailableReplicas
for idx, item := range m.GetDeploymentConditions() {
_, _ = idx, item
if v, ok := interface{}(item).(interface{ Validate() error }); ok {
if err := v.Validate(); err != nil {
return Deployment_DeploymentStatusValidationError{
field: fmt.Sprintf("DeploymentConditions[%v]", idx),
reason: "embedded message failed validation",
cause: err,
}
}
}
}
return nil
}
// Deployment_DeploymentStatusValidationError is the validation error returned
// by Deployment_DeploymentStatus.Validate if the designated constraints
// aren't met.
type Deployment_DeploymentStatusValidationError struct {
field string
reason string
cause error
key bool
}
// Field function returns field value.
func (e Deployment_DeploymentStatusValidationError) Field() string { return e.field }
// Reason function returns reason value.
func (e Deployment_DeploymentStatusValidationError) Reason() string { return e.reason }
// Cause function returns cause value.
func (e Deployment_DeploymentStatusValidationError) Cause() error { return e.cause }
// Key function returns key value.
func (e Deployment_DeploymentStatusValidationError) Key() bool { return e.key }
// ErrorName returns error name.
func (e Deployment_DeploymentStatusValidationError) ErrorName() string {
return "Deployment_DeploymentStatusValidationError"
}
// Error satisfies the builtin error interface
func (e Deployment_DeploymentStatusValidationError) 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 %sDeployment_DeploymentStatus.%s: %s%s",
key,
e.field,
e.reason,
cause)
}
var _ error = Deployment_DeploymentStatusValidationError{}
var _ interface {
Field() string
Reason() string
Key() bool
Cause() error
ErrorName() string
} = Deployment_DeploymentStatusValidationError{}
// Validate checks the field values on Deployment_DeploymentStatus_Condition
// with the rules defined in the proto definition for this message. If any
// rules are violated, an error is returned.
func (m *Deployment_DeploymentStatus_Condition) Validate() error {
if m == nil {
return nil
}
// no validation rules for Type
// no validation rules for ConditionStatus
// no validation rules for Reason
// no validation rules for Message
return nil
}
// Deployment_DeploymentStatus_ConditionValidationError is the validation error
// returned by Deployment_DeploymentStatus_Condition.Validate if the
// designated constraints aren't met.
type Deployment_DeploymentStatus_ConditionValidationError struct {
field string
reason string
cause error
key bool
}
// Field function returns field value.
func (e Deployment_DeploymentStatus_ConditionValidationError) Field() string { return e.field }
// Reason function returns reason value.
func (e Deployment_DeploymentStatus_ConditionValidationError) Reason() string { return e.reason }
// Cause function returns cause value.
func (e Deployment_DeploymentStatus_ConditionValidationError) Cause() error { return e.cause }
// Key function returns key value.
func (e Deployment_DeploymentStatus_ConditionValidationError) Key() bool { return e.key }
// ErrorName returns error name.
func (e Deployment_DeploymentStatus_ConditionValidationError) ErrorName() string {
return "Deployment_DeploymentStatus_ConditionValidationError"
}
// Error satisfies the builtin error interface
func (e Deployment_DeploymentStatus_ConditionValidationError) 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 %sDeployment_DeploymentStatus_Condition.%s: %s%s",
key,
e.field,
e.reason,
cause)
}
var _ error = Deployment_DeploymentStatus_ConditionValidationError{}
var _ interface {
Field() string
Reason() string
Key() bool
Cause() error
ErrorName() string
} = Deployment_DeploymentStatus_ConditionValidationError{}
// Validate checks the field values on UpdateDeploymentRequest_Fields with the
// rules defined in the proto definition for this message. If any rules are
// violated, an error is returned.
......
......@@ -2,10 +2,12 @@ package k8s
import (
"context"
"strings"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
......@@ -63,11 +65,54 @@ func ProtoForDeployment(cluster string, deployment *appsv1.Deployment) *k8sapiv1
clusterName = cluster
}
return &k8sapiv1.Deployment{
Cluster: clusterName,
Namespace: deployment.Namespace,
Name: deployment.Name,
Labels: deployment.Labels,
Annotations: deployment.Annotations,
Cluster: clusterName,
Namespace: deployment.Namespace,
Name: deployment.Name,
Labels: deployment.Labels,
Annotations: deployment.Annotations,
DeploymentStatus: ProtoForDeploymentStatus(deployment.Status),
}
}
func ProtoForDeploymentStatus(deploymentStatus appsv1.DeploymentStatus) *k8sapiv1.Deployment_DeploymentStatus {
var deploymentConditions []*k8sapiv1.Deployment_DeploymentStatus_Condition
for _, cond := range deploymentStatus.Conditions {
var deploymentConditionType k8sapiv1.Deployment_DeploymentStatus_Condition_Type
// TODO: Is this the preferred way of converting from one enum to another?
if cond.Type != "" {
deploymentConditionType = k8sapiv1.Deployment_DeploymentStatus_Condition_Type(
k8sapiv1.Deployment_DeploymentStatus_Condition_Type_value[strings.ToUpper(string(cond.Type))])
}
var condStatus k8sapiv1.Deployment_DeploymentStatus_Condition_ConditionStatus
switch cond.Status {
case v1.ConditionTrue:
{
condStatus = k8sapiv1.Deployment_DeploymentStatus_Condition_CONDITION_TRUE
}
case v1.ConditionFalse:
{
condStatus = k8sapiv1.Deployment_DeploymentStatus_Condition_CONDITION_FALSE
}
default:
condStatus = k8sapiv1.Deployment_DeploymentStatus_Condition_CONDITION_UNKNOWN
}
newCond := &k8sapiv1.Deployment_DeploymentStatus_Condition{
Type: deploymentConditionType,
ConditionStatus: condStatus,
Reason: cond.Reason,
Message: cond.Message,
}
deploymentConditions = append(deploymentConditions, newCond)
}
return &k8sapiv1.Deployment_DeploymentStatus{
Replicas: uint32(deploymentStatus.Replicas),
UpdatedReplicas: uint32(deploymentStatus.UpdatedReplicas),
ReadyReplicas: uint32(deploymentStatus.ReadyReplicas),
AvailableReplicas: uint32(deploymentStatus.AvailableReplicas),
UnavailableReplicas: uint32(deploymentStatus.UnavailableReplicas),
DeploymentConditions: deploymentConditions,
}
}
......
......@@ -6,6 +6,7 @@ import (
"github.com/stretchr/testify/assert"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8s "k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/fake"
......@@ -245,3 +246,65 @@ func TestProtoForDeploymentClusterName(t *testing.T) {
})
}
}
func TestProtoForDeploymentStatus(t *testing.T) {
t.Parallel()
var deploymentTestCases = []struct {
id string
deployment *appsv1.Deployment
}{
{
id: "foo",
deployment: &appsv1.Deployment{
Status: appsv1.DeploymentStatus{
Replicas: 60,
UpdatedReplicas: 60,
AvailableReplicas: 10,
UnavailableReplicas: 20,
Conditions: []appsv1.DeploymentCondition{
{
Type: appsv1.DeploymentAvailable,
Status: v1.ConditionTrue,
Reason: "reason",
Message: "message",
},
},
},
},
},
{
id: "oof",
deployment: &appsv1.Deployment{
Status: appsv1.DeploymentStatus{
Replicas: 40,
UpdatedReplicas: 31,
AvailableReplicas: 3,
UnavailableReplicas: 8,
Conditions: []appsv1.DeploymentCondition{
{
Type: appsv1.DeploymentReplicaFailure,
Status: v1.ConditionFalse,
Reason: "space",
Message: "moon",
},
},
},
},
},
}
for _, tt := range deploymentTestCases {
tt := tt
t.Run(tt.id, func(t *testing.T) {
t.Parallel()
deployment := ProtoForDeployment("", tt.deployment)
assert.Equal(t, tt.deployment.Status.Replicas, int32(deployment.DeploymentStatus.Replicas))
assert.Equal(t, tt.deployment.Status.UpdatedReplicas, int32(deployment.DeploymentStatus.UpdatedReplicas))
assert.Equal(t, tt.deployment.Status.ReadyReplicas, int32(deployment.DeploymentStatus.ReadyReplicas))
assert.Equal(t, tt.deployment.Status.AvailableReplicas, int32(deployment.DeploymentStatus.AvailableReplicas))
assert.Equal(t, len(tt.deployment.Status.Conditions), len(deployment.DeploymentStatus.DeploymentConditions))
})
}
}
......@@ -11187,6 +11187,9 @@ export namespace clutch {
 
/** Deployment annotations */
annotations?: ({ [k: string]: string }|null);
/** Deployment deploymentStatus */
deploymentStatus?: (clutch.k8s.v1.Deployment.IDeploymentStatus|null);
}
 
/** Represents a Deployment. */
......@@ -11213,6 +11216,9 @@ export namespace clutch {
/** Deployment annotations. */
public annotations: { [k: string]: string };
 
/** Deployment deploymentStatus. */
public deploymentStatus?: (clutch.k8s.v1.Deployment.IDeploymentStatus|null);
/**
* Verifies a Deployment message.
* @param message Plain object to verify
......@@ -11242,6 +11248,176 @@ export namespace clutch {
public toJSON(): { [k: string]: any };
}
 
namespace Deployment {
/** Properties of a DeploymentStatus. */
interface IDeploymentStatus {
/** DeploymentStatus replicas */
replicas?: (number|null);
/** DeploymentStatus updatedReplicas */
updatedReplicas?: (number|null);
/** DeploymentStatus readyReplicas */
readyReplicas?: (number|null);
/** DeploymentStatus availableReplicas */
availableReplicas?: (number|null);
/** DeploymentStatus unavailableReplicas */
unavailableReplicas?: (number|null);
/** DeploymentStatus deploymentConditions */
deploymentConditions?: (clutch.k8s.v1.Deployment.DeploymentStatus.ICondition[]|null);
}
/** Represents a DeploymentStatus. */
class DeploymentStatus implements IDeploymentStatus {
/**
* Constructs a new DeploymentStatus.
* @param [properties] Properties to set
*/
constructor(properties?: clutch.k8s.v1.Deployment.IDeploymentStatus);
/** DeploymentStatus replicas. */
public replicas: number;
/** DeploymentStatus updatedReplicas. */
public updatedReplicas: number;
/** DeploymentStatus readyReplicas. */
public readyReplicas: number;
/** DeploymentStatus availableReplicas. */
public availableReplicas: number;
/** DeploymentStatus unavailableReplicas. */
public unavailableReplicas: number;
/** DeploymentStatus deploymentConditions. */
public deploymentConditions: clutch.k8s.v1.Deployment.DeploymentStatus.ICondition[];
/**
* Verifies a DeploymentStatus 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 DeploymentStatus message from a plain object. Also converts values to their respective internal types.
* @param object Plain object
* @returns DeploymentStatus
*/
public static fromObject(object: { [k: string]: any }): clutch.k8s.v1.Deployment.DeploymentStatus;
/**
* Creates a plain object from a DeploymentStatus message. Also converts values to other types if specified.
* @param message DeploymentStatus
* @param [options] Conversion options
* @returns Plain object
*/
public static toObject(message: clutch.k8s.v1.Deployment.DeploymentStatus, options?: $protobuf.IConversionOptions): { [k: string]: any };
/**
* Converts this DeploymentStatus to JSON.
* @returns JSON object
*/
public toJSON(): { [k: string]: any };
}
namespace DeploymentStatus {
/** Properties of a Condition. */
interface ICondition {
/** Condition type */
type?: (clutch.k8s.v1.Deployment.DeploymentStatus.Condition.Type|null);
/** Condition conditionStatus */
conditionStatus?: (clutch.k8s.v1.Deployment.DeploymentStatus.Condition.ConditionStatus|null);
/** Condition reason */
reason?: (string|null);
/** Condition message */
message?: (string|null);
}
/** Represents a Condition. */
class Condition implements ICondition {
/**
* Constructs a new Condition.
* @param [properties] Properties to set
*/
constructor(properties?: clutch.k8s.v1.Deployment.DeploymentStatus.ICondition);
/** Condition type. */
public type: clutch.k8s.v1.Deployment.DeploymentStatus.Condition.Type;
/** Condition conditionStatus. */
public conditionStatus: clutch.k8s.v1.Deployment.DeploymentStatus.Condition.ConditionStatus;
/** Condition reason. */
public reason: string;
/** Condition message. */
public message: string;
/**
* Verifies a Condition 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 Condition message from a plain object. Also converts values to their respective internal types.
* @param object Plain object
* @returns Condition
*/
public static fromObject(object: { [k: string]: any }): clutch.k8s.v1.Deployment.DeploymentStatus.Condition;
/**
* Creates a plain object from a Condition message. Also converts values to other types if specified.
* @param message Condition
* @param [options] Conversion options
* @returns Plain object
*/
public static toObject(message: clutch.k8s.v1.Deployment.DeploymentStatus.Condition, options?: $protobuf.IConversionOptions): { [k: string]: any };
/**
* Converts this Condition to JSON.
* @returns JSON object
*/
public toJSON(): { [k: string]: any };
}
namespace Condition {
/** Type enum. */
enum Type {
UNSPECIFIED = 0,
UNKNOWN = 1,
AVAILABLE = 2,
PROGRESSING = 3,
REPLICA_FAILURE = 4
}
/** ConditionStatus enum. */
enum ConditionStatus {
CONDITION_UNSPECIFIED = 0,
CONDITION_TRUE = 1,
CONDITION_FALSE = 2,
CONDITION_UNKNOWN = 3
}
}
}
}
/** Properties of a DescribeDeploymentRequest. */
interface IDescribeDeploymentRequest {
 
......
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