-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from oviceinc/sre-1760/watch-argo
SRE-1760: Watch ArgoRollout resources that is specified in RolloutSca…
- Loading branch information
Showing
11 changed files
with
398 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Rollout | ||
metadata: | ||
name: rollout-sample | ||
spec: | ||
replicas: 2 | ||
revisionHistoryLimit: 2 | ||
selector: | ||
matchLabels: | ||
app: rollout-sample | ||
template: | ||
metadata: | ||
labels: | ||
app: rollout-sample | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx:1.25.0 | ||
imagePullPolicy: Always | ||
ports: | ||
- containerPort: 80 | ||
strategy: | ||
blueGreen: | ||
activeService: rollout-bluegreen-active | ||
previewService: rollout-bluegreen-preview | ||
autoPromotionEnabled: true | ||
# Do not scaleDown from ArgoRollout | ||
scaleDownDelaySeconds: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
## Append samples of your project ## | ||
namespace: rollout-test | ||
|
||
resources: | ||
- service.yaml | ||
- argorollout.yaml | ||
- rollout_v1alpha1_rolloutscaledown.yaml | ||
#+kubebuilder:scaffold:manifestskustomizesamples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: rollout-bluegreen-active | ||
spec: | ||
ports: | ||
- port: 80 | ||
protocol: TCP | ||
targetPort: 80 | ||
selector: | ||
app: rollout-sample | ||
type: ClusterIP | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: rollout-bluegreen-preview | ||
spec: | ||
ports: | ||
- port: 80 | ||
protocol: TCP | ||
targetPort: 80 | ||
selector: | ||
app: rollout-sample | ||
type: ClusterIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package controller | ||
|
||
import ( | ||
"context" | ||
|
||
argorolloutsapiv1alpha1 "github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/types" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
|
||
optimizerv1alpha1 "github.com/oviceinc/rollout-optimizer-controller/api/v1alpha1" | ||
) | ||
|
||
type ArgoRolloutReconciler struct { | ||
client.Client | ||
Scheme *runtime.Scheme | ||
} | ||
|
||
//+kubebuilder:rbac:groups=argoproj.io,resources=rollouts,verbs=get;list;watch | ||
//+kubebuilder:rbac:groups=argoproj.io,resources=rollouts/status,verbs=get | ||
//+kubebuilder:rbac:groups=rollout.ovice.com,resources=rolloutscaledowns,verbs=get;list;watch;create;update;patch;delete | ||
//+kubebuilder:rbac:groups=rollout.ovice.com,resources=rolloutscaledowns/status,verbs=get;update;patch | ||
//+kubebuilder:rbac:groups=rollout.ovice.com,resources=rolloutscaledowns/finalizers,verbs=update | ||
|
||
func (r *ArgoRolloutReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
logger := log.FromContext(ctx) | ||
scaleDownList := &optimizerv1alpha1.RolloutScaleDownList{} | ||
err := r.List(ctx, scaleDownList) | ||
if err != nil { | ||
logger.V(1).Error(err, "Faild to list RolloutScaleDown") | ||
return ctrl.Result{}, err | ||
} | ||
var targetScaleDown *optimizerv1alpha1.RolloutScaleDown | ||
for i := range scaleDownList.Items { | ||
item := scaleDownList.Items[i] | ||
if item.Namespace == req.Namespace && item.Spec.TargetRollout == req.Name { | ||
targetScaleDown = &item | ||
} | ||
} | ||
if targetScaleDown == nil { | ||
logger.V(2).Info("Not target of ScaleDown", req.Namespace, req.Name) | ||
return ctrl.Result{}, nil | ||
} | ||
argoRollout := &argorolloutsapiv1alpha1.Rollout{} | ||
err = r.Get(ctx, types.NamespacedName{Name: req.Name, Namespace: req.Namespace}, argoRollout) | ||
if err != nil && errors.IsNotFound(err) { | ||
logger.V(1).Info("Not found ArgoRollout", req.Namespace, req.Name) | ||
return ctrl.Result{}, nil | ||
} else if err != nil { | ||
logger.V(1).Error(err, "Failed to get ArgoRollout", req.Namespace, req.Name) | ||
return ctrl.Result{}, err | ||
} | ||
|
||
logger.V(1).Info("Target ArgoRollout", argoRollout.Namespace, argoRollout.Name) | ||
// TODO: Check ArgoRollout status and scaledown if needed | ||
|
||
return ctrl.Result{}, nil | ||
} | ||
|
||
func (r *ArgoRolloutReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||
return ctrl.NewControllerManagedBy(mgr).For(&argorolloutsapiv1alpha1.Rollout{}).Complete(r) | ||
} |
This file was deleted.
Oops, something went wrong.