Skip to content

Commit

Permalink
Merge pull request #58 from janlauber/56-rollout-strategy
Browse files Browse the repository at this point in the history
feat: Add CronJobSpec to RolloutSpec
  • Loading branch information
janlauber authored May 22, 2024
2 parents 1ef0337 + 5d1a554 commit 0acf2e1
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 1 deletion.
Binary file modified .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ Dockerfile.cross
*~
vendor/

test.yaml
test.yaml
.DS_Store
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ metadata:
spec:
args: ["nginx", "-g", "daemon off;"]
command: ["nginx"]
rolloutStrategy: rollingUpdate # or "recreate"
image:
registry: "docker.io"
repository: "nginx"
Expand Down
7 changes: 7 additions & 0 deletions api/v1alpha1/rollout_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ type CronJobSpec struct {
type RolloutSpec struct {
Args []string `json:"args,omitempty"`
Command []string `json:"command,omitempty"`
RolloutStrategy string `json:"rolloutStrategy,omitempty"`
Image ImageSpec `json:"image"`
SecurityContext SecurityContextSpec `json:"securityContext,omitempty"`
HorizontalScale HorizontalScaleSpec `json:"horizontalScale"`
Expand Down Expand Up @@ -174,6 +175,12 @@ type RolloutStatus struct {
//+kubebuilder:printcolumn:name="ImageTag",type="string",JSONPath=".spec.image.tag"
//+kubebuilder:printcolumn:name="Replicas",type="integer",JSONPath=".spec.horizontalScale.minReplicas"
//+kubebuilder:printcolumn:name="Deployment Status",type="string",JSONPath=".status.deployment.status"
//+kubebuilder:printcolumn:name="Service Status",type="string",JSONPath=".status.services[*].status"
//+kubebuilder:printcolumn:name="Ingress Status",type="string",JSONPath=".status.ingresses[*].status"
//+kubebuilder:printcolumn:name="Volume Status",type="string",JSONPath=".status.volumes[*].status"
//+kubebuilder:printcolumn:name="Service Account",type="string",JSONPath=".spec.serviceAccountName"
//+kubebuilder:printcolumn:name="Rollout Strategy",type="string",JSONPath=".spec.rolloutStrategy"
//+kubebuilder:printcolumn:name="Creation Timestamp",type="date",JSONPath=".metadata.creationTimestamp"
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

// +kubebuilder:object:root=true
Expand Down
Binary file modified config/.DS_Store
Binary file not shown.
20 changes: 20 additions & 0 deletions config/crd/bases/one-click.dev_rollouts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ spec:
- jsonPath: .status.deployment.status
name: Deployment Status
type: string
- jsonPath: .status.services[*].status
name: Service Status
type: string
- jsonPath: .status.ingresses[*].status
name: Ingress Status
type: string
- jsonPath: .status.volumes[*].status
name: Volume Status
type: string
- jsonPath: .spec.serviceAccountName
name: Service Account
type: string
- jsonPath: .spec.rolloutStrategy
name: Rollout Strategy
type: string
- jsonPath: .metadata.creationTimestamp
name: Creation Timestamp
type: date
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
Expand Down Expand Up @@ -257,6 +275,8 @@ spec:
- limits
- requests
type: object
rolloutStrategy:
type: string
secrets:
items:
properties:
Expand Down
46 changes: 46 additions & 0 deletions controllers/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ func (r *RolloutReconciler) deploymentForRollout(ctx context.Context, f *oneclic
}
}

// Determine the rollout strategy
strategy := appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
}

if f.Spec.RolloutStrategy != "" {
switch f.Spec.RolloutStrategy {
case "recreate":
strategy.Type = appsv1.RecreateDeploymentStrategyType
case "rollingUpdate":
strategy.Type = appsv1.RollingUpdateDeploymentStrategyType
default:
strategy.Type = appsv1.RollingUpdateDeploymentStrategyType
}
}

dep := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: f.Name,
Expand All @@ -102,6 +118,7 @@ func (r *RolloutReconciler) deploymentForRollout(ctx context.Context, f *oneclic
ImagePullSecrets: imagePullSecrets,
},
},
Strategy: strategy,
},
}

Expand Down Expand Up @@ -267,6 +284,35 @@ func needsUpdate(current *appsv1.Deployment, f *oneclickiov1alpha1.Rollout) bool
return true
}

// Check command
if !reflect.DeepEqual(current.Spec.Template.Spec.Containers[0].Command, f.Spec.Command) {
return true
}

// Check args
if !reflect.DeepEqual(current.Spec.Template.Spec.Containers[0].Args, f.Spec.Args) {
return true
}

// Check rollout strategy
strategy := appsv1.DeploymentStrategy{
Type: appsv1.RollingUpdateDeploymentStrategyType,
}
if f.Spec.RolloutStrategy != "" {
switch f.Spec.RolloutStrategy {
case "recreate":
strategy.Type = appsv1.RecreateDeploymentStrategyType
case "rollingUpdate":
strategy.Type = appsv1.RollingUpdateDeploymentStrategyType
default:
strategy.Type = appsv1.RollingUpdateDeploymentStrategyType
}
}

if !reflect.DeepEqual(current.Spec.Strategy, strategy) {
return true
}

// Add more checks as necessary, e.g., labels, annotations, specific configuration, etc.

return false
Expand Down

0 comments on commit 0acf2e1

Please sign in to comment.