Skip to content

Commit fcd0e30

Browse files
feat: add argo rollouts resume support (#220)
* add argo rollouts resume support * fix gofmt * fix linter * prevent second promotion * add rollback * apply review comments * fix health status * use status code * kick service reconciler on rollout promote --------- Co-authored-by: michaeljguarino <[email protected]>
1 parent a3cbfb6 commit fcd0e30

File tree

8 files changed

+375
-21
lines changed

8 files changed

+375
-21
lines changed

cmd/agent/main.go

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
package main
22

33
import (
4+
"net/http"
45
"os"
6+
"time"
57

8+
"github.com/argoproj/argo-rollouts/pkg/apis/rollouts"
9+
rolloutv1alpha1 "github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1"
10+
roclientset "github.com/argoproj/argo-rollouts/pkg/client/clientset/versioned"
611
templatesv1 "github.com/open-policy-agent/frameworks/constraint/pkg/apis/templates/v1"
712
constraintstatusv1beta1 "github.com/open-policy-agent/gatekeeper/v3/apis/status/v1beta1"
813
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
914
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1015
"k8s.io/apimachinery/pkg/runtime"
1116
"k8s.io/apimachinery/pkg/runtime/schema"
1217
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
18+
"k8s.io/client-go/dynamic"
19+
"k8s.io/client-go/kubernetes"
1320
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
1421
ctrl "sigs.k8s.io/controller-runtime"
1522
"sigs.k8s.io/controller-runtime/pkg/healthz"
@@ -32,9 +39,15 @@ func init() {
3239
utilruntime.Must(apiextensionsv1.AddToScheme(scheme))
3340
utilruntime.Must(constraintstatusv1beta1.AddToScheme(scheme))
3441
utilruntime.Must(templatesv1.AddToScheme(scheme))
42+
utilruntime.Must(rolloutv1alpha1.AddToScheme(scheme))
3543
//+kubebuilder:scaffold:scheme
3644
}
3745

46+
const (
47+
httpClientTimout = time.Second * 5
48+
httpCacheExpiryTime = time.Second * 2
49+
)
50+
3851
func main() {
3952
opt := newOptions()
4053
config := ctrl.GetConfigOrDie()
@@ -50,7 +63,21 @@ func main() {
5063
setupLog.Error(err, "unable to create manager")
5164
os.Exit(1)
5265
}
53-
66+
rolloutsClient, err := roclientset.NewForConfig(config)
67+
if err != nil {
68+
setupLog.Error(err, "unable to create rollouts client")
69+
os.Exit(1)
70+
}
71+
dynamicClient, err := dynamic.NewForConfig(config)
72+
if err != nil {
73+
setupLog.Error(err, "unable to create dynamic client")
74+
os.Exit(1)
75+
}
76+
kubeClient, err := kubernetes.NewForConfig(config)
77+
if err != nil {
78+
setupLog.Error(err, "unable to create kubernetes client")
79+
os.Exit(1)
80+
}
5481
setupLog.Info("starting agent")
5582
ctrlMgr, serviceReconciler, gateReconciler := runAgent(opt, config, ctx, mgr.GetClient())
5683

@@ -70,6 +97,17 @@ func main() {
7097
ConsoleClient: ctrlMgr.GetClient(),
7198
Reader: mgr.GetCache(),
7299
}
100+
argoRolloutController := &controller.ArgoRolloutReconciler{
101+
Client: mgr.GetClient(),
102+
Scheme: mgr.GetScheme(),
103+
ConsoleClient: ctrlMgr.GetClient(),
104+
ConsoleURL: opt.consoleUrl,
105+
HttpClient: &http.Client{Timeout: httpClientTimout},
106+
ArgoClientSet: rolloutsClient,
107+
DynamicClient: dynamicClient,
108+
SvcReconciler: serviceReconciler,
109+
KubeClient: kubeClient,
110+
}
73111

74112
reconcileGroups := map[schema.GroupVersionKind]controller.SetupWithManager{
75113
{
@@ -87,6 +125,11 @@ func main() {
87125
Version: "v1beta1",
88126
Kind: "ConstraintPodStatus",
89127
}: constraintController.SetupWithManager,
128+
{
129+
Group: rolloutv1alpha1.SchemeGroupVersion.Group,
130+
Version: rolloutv1alpha1.SchemeGroupVersion.Version,
131+
Kind: rollouts.RolloutKind,
132+
}: argoRolloutController.SetupWithManager,
90133
}
91134

92135
if err = (&controller.CrdRegisterControllerReconciler{

go.mod

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/Masterminds/semver/v3 v3.2.1
77
github.com/Masterminds/sprig/v3 v3.2.3
88
github.com/Yamashou/gqlgenc v0.18.1
9+
github.com/argoproj/argo-rollouts v1.6.6
910
github.com/elastic/crd-ref-docs v0.0.12
1011
github.com/evanphx/json-patch v5.7.0+incompatible
1112
github.com/fluxcd/flagger v1.35.0
@@ -19,7 +20,7 @@ require (
1920
github.com/open-policy-agent/gatekeeper/v3 v3.15.1
2021
github.com/orcaman/concurrent-map/v2 v2.0.1
2122
github.com/pkg/errors v0.9.1
22-
github.com/pluralsh/console-client-go v0.5.18
23+
github.com/pluralsh/console-client-go v0.7.0
2324
github.com/pluralsh/controller-reconcile-helper v0.0.4
2425
github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34
2526
github.com/pluralsh/polly v0.1.10
@@ -87,7 +88,7 @@ require (
8788
github.com/docker/go-units v0.5.0 // indirect
8889
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
8990
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
90-
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
91+
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect
9192
github.com/fatih/camelcase v1.0.0 // indirect
9293
github.com/fatih/color v1.16.0 // indirect
9394
github.com/felixge/httpsnoop v1.0.4 // indirect
@@ -111,7 +112,7 @@ require (
111112
github.com/gogo/protobuf v1.3.2 // indirect
112113
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
113114
github.com/golang/protobuf v1.5.4 // indirect
114-
github.com/google/btree v1.0.1 // indirect
115+
github.com/google/btree v1.1.2 // indirect
115116
github.com/google/cel-go v0.17.7 // indirect
116117
github.com/google/gnostic-models v0.6.8 // indirect
117118
github.com/google/go-cmp v0.6.0 // indirect
@@ -122,7 +123,7 @@ require (
122123
github.com/gorilla/mux v1.8.1 // indirect
123124
github.com/gorilla/websocket v1.5.0 // indirect
124125
github.com/gosuri/uitable v0.0.4 // indirect
125-
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
126+
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
126127
github.com/hashicorp/errwrap v1.1.0 // indirect
127128
github.com/hashicorp/go-multierror v1.1.1 // indirect
128129
github.com/hashicorp/hcl v1.0.0 // indirect
@@ -184,7 +185,7 @@ require (
184185
github.com/sirupsen/logrus v1.9.3 // indirect
185186
github.com/sosodev/duration v1.2.0 // indirect
186187
github.com/spf13/afero v1.9.3 // indirect
187-
github.com/spf13/cast v1.5.0 // indirect
188+
github.com/spf13/cast v1.5.1 // indirect
188189
github.com/spf13/cobra v1.8.0 // indirect
189190
github.com/spf13/jwalterweatherman v1.1.0 // indirect
190191
github.com/spf13/viper v1.15.0 // indirect

go.sum

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNg
8181
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
8282
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df h1:7RFfzj4SSt6nnvCPbCqijJi1nWCd+TqAT3bYCStRC18=
8383
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230305170008-8188dc5388df/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM=
84+
github.com/argoproj/argo-rollouts v1.6.6 h1:JCJ0cGAwWkh2xCAHZ1OQmrobysRjCatmG9IZaLJpS1g=
85+
github.com/argoproj/argo-rollouts v1.6.6/go.mod h1:X2kTiBaYCSounmw1kmONdIZTwJNzNQYC0SrXUgSw9UI=
8486
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
8587
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
8688
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
@@ -173,8 +175,8 @@ github.com/evanphx/json-patch v5.7.0+incompatible h1:vgGkfT/9f8zE6tvSCe74nfpAVDQ
173175
github.com/evanphx/json-patch v5.7.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
174176
github.com/evanphx/json-patch/v5 v5.8.0 h1:lRj6N9Nci7MvzrXuX6HFzU8XjmhPiXPlsKEy1u0KQro=
175177
github.com/evanphx/json-patch/v5 v5.8.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
176-
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d h1:105gxyaGwCFad8crR9dcMQWvV9Hvulu6hwUh4tWPJnM=
177-
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d/go.mod h1:ZZMPRZwes7CROmyNKgQzC3XPs6L/G2EJLHddWejkmf4=
178+
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f h1:Wl78ApPPB2Wvf/TIe2xdyJxTlb6obmF18d8QdkxNDu4=
179+
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f/go.mod h1:OSYXu++VVOHnXeitef/D8n/6y4QV8uLHSFXX4NeXMGc=
178180
github.com/fatih/camelcase v1.0.0 h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8=
179181
github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc=
180182
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
@@ -289,8 +291,8 @@ github.com/gomodule/redigo v1.8.2 h1:H5XSIre1MB5NbPYFp+i1NBbb5qN1W8Y8YAQoAYbkm8k
289291
github.com/gomodule/redigo v1.8.2/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
290292
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
291293
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
292-
github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
293-
github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
294+
github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU=
295+
github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
294296
github.com/google/cel-go v0.17.7 h1:6ebJFzu1xO2n7TLtN+UBqShGBhlD85bhvglh5DpcfqQ=
295297
github.com/google/cel-go v0.17.7/go.mod h1:HXZKzB0LXqer5lHHgfWAnlYwJaQBDKMjxjulNQzhwhY=
296298
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
@@ -345,8 +347,8 @@ github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWm
345347
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
346348
github.com/gosuri/uitable v0.0.4 h1:IG2xLKRvErL3uhY6e1BylFzG+aJiwQviDDTfOKeKTpY=
347349
github.com/gosuri/uitable v0.0.4/go.mod h1:tKR86bXuXPZazfOTG1FIzvjIdXzd0mo4Vtn16vt0PJo=
348-
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 h1:pdN6V1QBWetyv/0+wjACpqVH+eVULgEjkurDLq3goeM=
349-
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
350+
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 h1:+ngKgrYPPJrOjhax5N+uePQ0Fh1Z7PheYoUI/0nzkPA=
351+
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
350352
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho=
351353
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
352354
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
@@ -526,8 +528,8 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
526528
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
527529
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
528530
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
529-
github.com/pluralsh/console-client-go v0.5.18 h1:uwYsoGaggvi3uPZYL/+qdhvgl73sGBiuVUfQGAC/J4c=
530-
github.com/pluralsh/console-client-go v0.5.18/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
531+
github.com/pluralsh/console-client-go v0.7.0 h1:7BcvftmKhssYd8F06NGsWXKxs7O3K8gQDYrQebvbmHE=
532+
github.com/pluralsh/console-client-go v0.7.0/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
531533
github.com/pluralsh/controller-reconcile-helper v0.0.4 h1:1o+7qYSyoeqKFjx+WgQTxDz4Q2VMpzprJIIKShxqG0E=
532534
github.com/pluralsh/controller-reconcile-helper v0.0.4/go.mod h1:AfY0gtteD6veBjmB6jiRx/aR4yevEf6K0M13/pGan/s=
533535
github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34 h1:ab2PN+6if/Aq3/sJM0AVdy1SYuMAnq4g20VaKhTm/Bw=
@@ -590,8 +592,8 @@ github.com/sosodev/duration v1.2.0/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERA
590592
github.com/spf13/afero v1.9.3 h1:41FoI0fD7OR7mGcKE/aOiLkGreyf8ifIOQmJANWogMk=
591593
github.com/spf13/afero v1.9.3/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y=
592594
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
593-
github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w=
594-
github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU=
595+
github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA=
596+
github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48=
595597
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
596598
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
597599
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
package controller
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"net/http"
7+
"net/url"
8+
"time"
9+
10+
clientset "github.com/argoproj/argo-rollouts/pkg/client/clientset/versioned/typed/rollouts/v1alpha1"
11+
"github.com/argoproj/argo-rollouts/pkg/kubectl-argo-rollouts/cmd/abort"
12+
13+
"github.com/argoproj/argo-rollouts/pkg/apis/rollouts"
14+
rolloutv1alpha1 "github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1"
15+
roclientset "github.com/argoproj/argo-rollouts/pkg/client/clientset/versioned"
16+
console "github.com/pluralsh/console-client-go"
17+
"github.com/pluralsh/deployment-operator/internal/utils"
18+
"github.com/pluralsh/deployment-operator/pkg/client"
19+
"github.com/pluralsh/deployment-operator/pkg/controller/service"
20+
"k8s.io/apimachinery/pkg/runtime"
21+
"k8s.io/client-go/dynamic"
22+
"k8s.io/client-go/kubernetes"
23+
ctrl "sigs.k8s.io/controller-runtime"
24+
k8sClient "sigs.k8s.io/controller-runtime/pkg/client"
25+
"sigs.k8s.io/controller-runtime/pkg/log"
26+
)
27+
28+
const (
29+
inventoryAnnotationName = "config.k8s.io/owning-inventory"
30+
closed = "closed"
31+
)
32+
33+
var requeueRollout = ctrl.Result{RequeueAfter: time.Second * 5}
34+
35+
// ArgoRolloutReconciler reconciles a Argo Rollout custom resource.
36+
type ArgoRolloutReconciler struct {
37+
k8sClient.Client
38+
Scheme *runtime.Scheme
39+
ConsoleClient client.Client
40+
ConsoleURL string
41+
HttpClient *http.Client
42+
ArgoClientSet roclientset.Interface
43+
DynamicClient dynamic.Interface
44+
KubeClient kubernetes.Interface
45+
SvcReconciler *service.ServiceReconciler
46+
}
47+
48+
// Reconcile Argo Rollout custom resources to ensure that Console stays in sync with Kubernetes cluster.
49+
func (r *ArgoRolloutReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
50+
logger := log.FromContext(ctx)
51+
52+
// Read resource from Kubernetes cluster.
53+
rollout := &rolloutv1alpha1.Rollout{}
54+
if err := r.Get(ctx, req.NamespacedName, rollout); err != nil {
55+
logger.Error(err, "unable to fetch rollout")
56+
return ctrl.Result{}, k8sClient.IgnoreNotFound(err)
57+
}
58+
59+
if !rollout.DeletionTimestamp.IsZero() {
60+
return ctrl.Result{}, nil
61+
}
62+
63+
serviceID, ok := rollout.Annotations[inventoryAnnotationName]
64+
if !ok {
65+
return ctrl.Result{}, nil
66+
}
67+
if serviceID == "" {
68+
return ctrl.Result{}, fmt.Errorf("the service ID from the inventory annotation is empty")
69+
}
70+
service, err := r.ConsoleClient.GetService(serviceID)
71+
if err != nil {
72+
return ctrl.Result{}, err
73+
}
74+
consoleURL, err := sanitizeURL(r.ConsoleURL)
75+
if err != nil {
76+
return ctrl.Result{}, err
77+
}
78+
if rollout.Status.Phase == rolloutv1alpha1.RolloutPhasePaused {
79+
// wait until the agent will change component status
80+
if !hasPausedRolloutComponent(service) {
81+
return requeueRollout, nil
82+
}
83+
84+
rolloutIf := r.ArgoClientSet.ArgoprojV1alpha1().Rollouts(rollout.Namespace)
85+
promoteURL := fmt.Sprintf("%s/ext/v1/gate/%s", consoleURL, serviceID)
86+
rollbackURL := fmt.Sprintf("%s/ext/v1/rollback/%s", consoleURL, serviceID)
87+
88+
promoteResponse, err := r.get(promoteURL)
89+
if err != nil {
90+
return ctrl.Result{}, err
91+
}
92+
if promoteResponse == http.StatusOK {
93+
return ctrl.Result{}, r.promote(ctx, rolloutIf, rollout, serviceID)
94+
}
95+
rollbackResponse, err := r.get(rollbackURL)
96+
if err != nil {
97+
return ctrl.Result{}, err
98+
}
99+
if rollbackResponse == http.StatusOK {
100+
return ctrl.Result{}, r.rollback(rolloutIf, rollout)
101+
}
102+
return requeueRollout, nil
103+
}
104+
return ctrl.Result{}, nil
105+
}
106+
107+
func (r *ArgoRolloutReconciler) promote(ctx context.Context, rolloutIf clientset.RolloutInterface, rollout *rolloutv1alpha1.Rollout, svcId string) error {
108+
if _, err := utils.PromoteRollout(ctx, rolloutIf, rollout.Name); err != nil {
109+
return err
110+
}
111+
112+
if r.SvcReconciler != nil {
113+
r.SvcReconciler.SvcQueue.AddRateLimited(svcId)
114+
}
115+
return nil
116+
}
117+
118+
func (r *ArgoRolloutReconciler) rollback(rolloutIf clientset.RolloutInterface, rollout *rolloutv1alpha1.Rollout) error {
119+
if _, err := abort.AbortRollout(rolloutIf, rollout.Name); err != nil {
120+
return err
121+
}
122+
return nil
123+
}
124+
125+
func hasPausedRolloutComponent(service *console.GetServiceDeploymentForAgent_ServiceDeployment) bool {
126+
for _, component := range service.Components {
127+
if component.Kind == rollouts.RolloutKind {
128+
if component.State != nil && *component.State == console.ComponentStatePaused {
129+
return true
130+
}
131+
}
132+
}
133+
return false
134+
}
135+
136+
func sanitizeURL(consoleURL string) (string, error) {
137+
u, err := url.Parse(consoleURL)
138+
if err != nil {
139+
return "", err
140+
}
141+
return fmt.Sprintf("%s://%s", u.Scheme, u.Host), nil
142+
}
143+
144+
// SetupWithManager sets up the controller with the Manager.
145+
func (r *ArgoRolloutReconciler) SetupWithManager(mgr ctrl.Manager) error {
146+
return ctrl.NewControllerManagedBy(mgr).
147+
For(&rolloutv1alpha1.Rollout{}).
148+
Complete(r)
149+
}
150+
151+
func (r *ArgoRolloutReconciler) get(url string) (int, error) {
152+
// Make the HTTP request
153+
resp, err := r.HttpClient.Get(url)
154+
if err != nil {
155+
return http.StatusInternalServerError, err
156+
}
157+
defer resp.Body.Close()
158+
159+
return resp.StatusCode, nil
160+
}

0 commit comments

Comments
 (0)