Skip to content

Commit

Permalink
Resume command
Browse files Browse the repository at this point in the history
  • Loading branch information
dzsak committed Mar 27, 2024
1 parent e9966c4 commit a32e360
Show file tree
Hide file tree
Showing 13 changed files with 415 additions and 4 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ require (
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/onsi/gomega v1.31.1 // indirect
github.com/opencontainers/go-digest v1.0.1-0.20231025023718-d50d2fec9c98 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
Expand Down Expand Up @@ -136,6 +137,7 @@ require (
github.com/fluxcd/image-reflector-controller/api v0.31.2
github.com/fluxcd/kustomize-controller/api v1.2.2
github.com/fluxcd/notification-controller/api v1.2.4
github.com/fluxcd/pkg/runtime v0.44.1
github.com/fluxcd/source-controller/api v1.2.4
github.com/go-chi/chi v1.5.5
github.com/go-logr/logr v1.4.1 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ github.com/fluxcd/pkg/apis/kustomize v1.3.0 h1:qvB46CfaOWcL1SyR2RiVWN/j7/035D0Ot
github.com/fluxcd/pkg/apis/kustomize v1.3.0/go.mod h1:PCXf5kktTzNav0aH2Ns3jsowqwmA9xTcsrEOoPzx/K8=
github.com/fluxcd/pkg/apis/meta v1.3.0 h1:KxeEc6olmSZvQ5pBONPE4IKxyoWQbqTJF1X6K5nIXpU=
github.com/fluxcd/pkg/apis/meta v1.3.0/go.mod h1:3Ui8xFkoU4sYehqmscjpq7NjqH2YN1A2iX2okbO3/yA=
github.com/fluxcd/pkg/runtime v0.44.1 h1:XuPTcNIgn/NsoIo/A6qfPZaD9E7cbnJTDbeNw8O1SZQ=
github.com/fluxcd/pkg/runtime v0.44.1/go.mod h1:s1AhSOTCEBPaTfz/GdBD/Ws66uOByIuNP4Znrq+is9M=
github.com/fluxcd/source-controller/api v1.2.4 h1:XjKTWhSSeLGsogWnTcLl5sUnyMlC5TKDbbBgP9SyJ5c=
github.com/fluxcd/source-controller/api v1.2.4/go.mod h1:j3QSHpIPBP5sjaGIkVtsgWCx8JcOmcsutRmdJmRMOZg=
github.com/foxcpp/go-mockdns v1.0.0 h1:7jBqxd3WDWwi/6WhDvacvH1XsN3rOLXyHM1uhvIx6FI=
Expand Down Expand Up @@ -282,6 +284,8 @@ github.com/onsi/ginkgo/v2 v2.14.0 h1:vSmGj2Z5YPb9JwCWT6z6ihcUvDhuXLc3sJiqd3jMKAY
github.com/onsi/ginkgo/v2 v2.14.0/go.mod h1:JkUdW7JkN0V6rFvsHcJ478egV3XH9NxpD27Hal/PhZw=
github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8=
github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo=
github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0=
github.com/opencontainers/go-digest v1.0.1-0.20231025023718-d50d2fec9c98 h1:H55sU3giNgBkIvmAo0vI/AAFwVTwfWsf6MN3+9H6U8o=
github.com/opencontainers/go-digest v1.0.1-0.20231025023718-d50d2fec9c98/go.mod h1:RqnyioA3pIEZMkSbOIcrw32YSgETfn/VrLuEikEdPNU=
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
Expand Down
13 changes: 13 additions & 0 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,19 @@ func suspend(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("{}"))
}

func resume(w http.ResponseWriter, r *http.Request) {
resource := r.URL.Query().Get("resource")
namespace := r.URL.Query().Get("namespace")
name := r.URL.Query().Get("name")
config, _ := r.Context().Value("config").(*rest.Config)

reconcileCommand := flux.NewResumeCommand(resource)
go reconcileCommand.Run(config, namespace, name)

w.WriteHeader(http.StatusOK)
w.Write([]byte("{}"))
}

func reconcile(w http.ResponseWriter, r *http.Request) {
resource := r.URL.Query().Get("resource")
namespace := r.URL.Query().Get("namespace")
Expand Down
1 change: 1 addition & 0 deletions pkg/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func SetupRouter(
r.Get("/api/logs", streamLogs)
r.Get("/api/stopLogs", stopLogs)
r.Post("/api/suspend", suspend)
r.Post("/api/resume", resume)
r.Post("/api/reconcile", reconcile)
r.Get("/ws/", func(w http.ResponseWriter, r *http.Request) {
streaming.ServeWs(clientHub, w, r)
Expand Down
16 changes: 16 additions & 0 deletions pkg/flux/helmrelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ func (obj helmReleaseAdapter) setSuspended() {
obj.HelmRelease.Spec.Suspend = true
}

func (obj helmReleaseAdapter) setUnsuspended() {
obj.HelmRelease.Spec.Suspend = false
}

func (obj helmReleaseAdapter) getObservedGeneration() int64 {
return obj.HelmRelease.Status.ObservedGeneration
}

func (obj helmReleaseAdapter) isStatic() bool {
return false
}

func (obj helmReleaseAdapter) lastHandledReconcileRequest() string {
return obj.Status.GetLastHandledReconcileRequest()
}
Expand All @@ -67,3 +79,7 @@ func (h helmReleaseListAdapter) len() int {
func (a helmReleaseListAdapter) item(i int) suspendable {
return &helmReleaseAdapter{&a.HelmReleaseList.Items[i]}
}

func (a helmReleaseListAdapter) resumeItem(i int) resumable {
return &helmReleaseAdapter{&a.HelmReleaseList.Items[i]}
}
16 changes: 16 additions & 0 deletions pkg/flux/kustomization.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ func (obj kustomizationAdapter) setSuspended() {
obj.Kustomization.Spec.Suspend = true
}

func (obj kustomizationAdapter) setUnsuspended() {
obj.Kustomization.Spec.Suspend = false
}

func (obj kustomizationAdapter) getObservedGeneration() int64 {
return obj.Kustomization.Status.ObservedGeneration
}

func (obj kustomizationAdapter) isStatic() bool {
return false
}

func (obj kustomizationAdapter) lastHandledReconcileRequest() string {
return obj.Status.GetLastHandledReconcileRequest()
}
Expand All @@ -67,3 +79,7 @@ func (a kustomizationListAdapter) len() int {
func (a kustomizationListAdapter) item(i int) suspendable {
return &kustomizationAdapter{&a.KustomizationList.Items[i]}
}

func (a kustomizationListAdapter) resumeItem(i int) resumable {
return &kustomizationAdapter{&a.KustomizationList.Items[i]}
}
Loading

0 comments on commit a32e360

Please sign in to comment.