Skip to content

Commit

Permalink
add API
Browse files Browse the repository at this point in the history
Signed-off-by: Eytan Avisror <[email protected]>
  • Loading branch information
Eytan Avisror committed Jan 12, 2021
1 parent 2816490 commit 87afbd6
Show file tree
Hide file tree
Showing 11 changed files with 453 additions and 34 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 Intuit Inc..
Copyright 2021 Intuit Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
107 changes: 94 additions & 13 deletions api/v1alpha1/rollingupgrade_types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 Intuit Inc..
Copyright 2021 Intuit Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -17,29 +17,44 @@ limitations under the License.
package v1alpha1

import (
"fmt"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// RollingUpgradeSpec defines the desired state of RollingUpgrade
type RollingUpgradeSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Foo is an example field of RollingUpgrade. Edit rollingupgrade_types.go to remove/update
Foo string `json:"foo,omitempty"`
PostDrainDelaySeconds int `json:"postDrainDelaySeconds,omitempty"`
NodeIntervalSeconds int `json:"nodeIntervalSeconds,omitempty"`
AsgName string `json:"asgName,omitempty"`
PreDrain PreDrainSpec `json:"preDrain,omitempty"`
PostDrain PostDrainSpec `json:"postDrain,omitempty"`
PostTerminate PostTerminateSpec `json:"postTerminate,omitempty"`
Strategy UpdateStrategy `json:"strategy,omitempty"`
IgnoreDrainFailures bool `json:"ignoreDrainFailures,omitempty"`
ForceRefresh bool `json:"forceRefresh,omitempty"`
ReadinessGates []NodeReadinessGate `json:"readinessGates,omitempty"`
}

// RollingUpgradeStatus defines the observed state of RollingUpgrade
type RollingUpgradeStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
CurrentStatus string `json:"currentStatus,omitempty"`
StartTime string `json:"startTime,omitempty"`
EndTime string `json:"endTime,omitempty"`
TotalProcessingTime string `json:"totalProcessingTime,omitempty"`
NodesProcessed int `json:"nodesProcessed,omitempty"`
TotalNodes int `json:"totalNodes,omitempty"`
Conditions []RollingUpgradeCondition `json:"conditions,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=rollingupgrades,scope=Namespaced,shortName=ru
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.currentStatus",description="current status of the rollingupgarde"
// +kubebuilder:printcolumn:name="TotalNodes",type="string",JSONPath=".status.totalNodes",description="total nodes involved in the rollingupgarde"
// +kubebuilder:printcolumn:name="NodesProcessed",type="string",JSONPath=".status.nodesProcessed",description="current number of nodes processed in the rollingupgarde"

// RollingUpgrade is the Schema for the rollingupgrades API
type RollingUpgrade struct {
Expand All @@ -62,3 +77,69 @@ type RollingUpgradeList struct {
func init() {
SchemeBuilder.Register(&RollingUpgrade{}, &RollingUpgradeList{})
}

// PreDrainSpec contains the fields for actions taken before draining the node.
type PreDrainSpec struct {
Script string `json:"script,omitempty"`
}

// PostDrainSpec contains the fields for actions taken after draining the node.
type PostDrainSpec struct {
Script string `json:"script,omitempty"`
WaitSeconds int64 `json:"waitSeconds,omitempty"`
PostWaitScript string `json:"postWaitScript,omitempty"`
}

// PostTerminateSpec contains the fields for actions taken after terminating the node.
type PostTerminateSpec struct {
Script string `json:"script,omitempty"`
}

type NodeReadinessGate struct {
MatchLabels map[string]string `json:"matchLabels,omitempty" protobuf:"bytes,1,rep,name=matchLabels"`
}

const (
// Status
StatusRunning = "running"
StatusComplete = "completed"
StatusError = "error"

// Conditions
UpgradeComplete UpgradeConditionType = "Complete"
)

// RollingUpgradeCondition describes the state of the RollingUpgrade
type RollingUpgradeCondition struct {
Type UpgradeConditionType `json:"type,omitempty"`
Status corev1.ConditionStatus `json:"status,omitempty"`
}

type UpdateStrategyType string
type UpdateStrategyMode string
type UpgradeConditionType string

const (
RandomUpdateStrategy UpdateStrategyType = "randomUpdate"
UniformAcrossAzUpdateStrategy UpdateStrategyType = "uniformAcrossAzUpdate"

UpdateStrategyModeLazy UpdateStrategyMode = "lazy"
UpdateStrategyModeEager UpdateStrategyMode = "eager"
)

// UpdateStrategy holds the information needed to perform update based on different update strategies
type UpdateStrategy struct {
Type UpdateStrategyType `json:"type,omitempty"`
Mode UpdateStrategyMode `json:"mode,omitempty"`
MaxUnavailable intstr.IntOrString `json:"maxUnavailable,omitempty"`
DrainTimeout int `json:"drainTimeout"`
}

func (c UpdateStrategyMode) String() string {
return string(c)
}

// NamespacedName returns namespaced name of the object.
func (r RollingUpgrade) NamespacedName() string {
return fmt.Sprintf("%s/%s", r.Namespace, r.Name)
}
120 changes: 117 additions & 3 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 87afbd6

Please sign in to comment.