diff --git a/.DS_Store b/.DS_Store index 3d5e7c7..fb9667d 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.gitignore b/.gitignore index c545efd..7979895 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,5 @@ Dockerfile.cross *~ vendor/ -test.yaml \ No newline at end of file +test.yaml +.DS_Store diff --git a/README.md b/README.md index 1a8b6fb..fd80218 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ metadata: spec: args: ["nginx", "-g", "daemon off;"] command: ["nginx"] + rolloutStrategy: rollingUpdate # or "recreate" image: registry: "docker.io" repository: "nginx" diff --git a/api/v1alpha1/rollout_types.go b/api/v1alpha1/rollout_types.go index 7c8eec6..60cdf9c 100644 --- a/api/v1alpha1/rollout_types.go +++ b/api/v1alpha1/rollout_types.go @@ -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"` @@ -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 diff --git a/config/.DS_Store b/config/.DS_Store index 759eb66..99d95a3 100644 Binary files a/config/.DS_Store and b/config/.DS_Store differ diff --git a/config/crd/bases/one-click.dev_rollouts.yaml b/config/crd/bases/one-click.dev_rollouts.yaml index 569c954..1ffcd8a 100644 --- a/config/crd/bases/one-click.dev_rollouts.yaml +++ b/config/crd/bases/one-click.dev_rollouts.yaml @@ -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 @@ -257,6 +275,8 @@ spec: - limits - requests type: object + rolloutStrategy: + type: string secrets: items: properties: diff --git a/controllers/deployment.go b/controllers/deployment.go index ec261ad..393a98f 100644 --- a/controllers/deployment.go +++ b/controllers/deployment.go @@ -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, @@ -102,6 +118,7 @@ func (r *RolloutReconciler) deploymentForRollout(ctx context.Context, f *oneclic ImagePullSecrets: imagePullSecrets, }, }, + Strategy: strategy, }, } @@ -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