mirror of https://github.com/fluxcd/flux2.git
Implement suspend, resume, reconcile image-update
.. and refactor. These are all amenable to the adapter refactoring that has served well so far. Signed-off-by: Michael Bridgen <michael@weave.works>pull/538/head
parent
2bb09697ce
commit
d55d185044
@ -0,0 +1,62 @@
|
||||
/*
|
||||
Copyright 2020 The Flux authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
apimeta "k8s.io/apimachinery/pkg/api/meta"
|
||||
|
||||
autov1 "github.com/fluxcd/image-automation-controller/api/v1alpha1"
|
||||
meta "github.com/fluxcd/pkg/apis/meta"
|
||||
)
|
||||
|
||||
var reconcileImageUpdateCmd = &cobra.Command{
|
||||
Use: "image-update [name]",
|
||||
Short: "Reconcile an ImageUpdateAutomation",
|
||||
Long: `The reconcile auto image-update command triggers a reconciliation of an ImageUpdateAutomation resource and waits for it to finish.`,
|
||||
Example: ` # Trigger an automation run for an existing image update automation
|
||||
flux reconcile auto image-update latest-images
|
||||
`,
|
||||
RunE: reconcileCommand{
|
||||
humanKind: autov1.ImageUpdateAutomationKind,
|
||||
adapter: imageUpdateAutomationAdapter{&autov1.ImageUpdateAutomation{}},
|
||||
}.run,
|
||||
}
|
||||
|
||||
func init() {
|
||||
reconcileAutoCmd.AddCommand(reconcileImageUpdateCmd)
|
||||
}
|
||||
|
||||
func (obj imageUpdateAutomationAdapter) suspended() bool {
|
||||
return obj.ImageUpdateAutomation.Spec.Suspend
|
||||
}
|
||||
|
||||
func (obj imageUpdateAutomationAdapter) lastHandledReconcileRequest() string {
|
||||
return obj.Status.GetLastHandledReconcileRequest()
|
||||
}
|
||||
|
||||
func (obj imageUpdateAutomationAdapter) successMessage() string {
|
||||
if rc := apimeta.FindStatusCondition(obj.Status.Conditions, meta.ReadyCondition); rc != nil {
|
||||
return rc.Message
|
||||
}
|
||||
if obj.Status.LastAutomationRunTime != nil {
|
||||
return "last run " + obj.Status.LastAutomationRunTime.Time.Format(time.RFC3339)
|
||||
}
|
||||
return "automation not yet run"
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
Copyright 2020 The Flux authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
autov1 "github.com/fluxcd/image-automation-controller/api/v1alpha1"
|
||||
)
|
||||
|
||||
var resumeImageUpdateCmd = &cobra.Command{
|
||||
Use: "image-update [name]",
|
||||
Short: "Resume a suspended ImageUpdateAutomation",
|
||||
Long: `The resume command marks a previously suspended ImageUpdateAutomation resource for reconciliation and waits for it to finish.`,
|
||||
Example: ` # Resume reconciliation for an existing ImageUpdateAutomation
|
||||
flux resume auto image-update latest-images
|
||||
`,
|
||||
RunE: resumeCommand{
|
||||
kind: autov1.ImageUpdateAutomationKind,
|
||||
humanKind: "image update automation",
|
||||
object: imageUpdateAutomationAdapter{&autov1.ImageUpdateAutomation{}},
|
||||
}.run,
|
||||
}
|
||||
|
||||
func init() {
|
||||
resumeAutoCmd.AddCommand(resumeImageUpdateCmd)
|
||||
}
|
||||
|
||||
func (obj imageUpdateAutomationAdapter) setUnsuspended() {
|
||||
obj.ImageUpdateAutomation.Spec.Suspend = false
|
||||
}
|
||||
|
||||
func (obj imageUpdateAutomationAdapter) getObservedGeneration() int64 {
|
||||
return obj.ImageUpdateAutomation.Status.ObservedGeneration
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
Copyright 2020 The Flux authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
apimeta "k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
"github.com/fluxcd/pkg/apis/meta"
|
||||
)
|
||||
|
||||
// statusable is used to see if a resource is considered ready in the usual way
|
||||
type statusable interface {
|
||||
adapter
|
||||
// this is implemented by ObjectMeta
|
||||
GetGeneration() int64
|
||||
getObservedGeneration() int64
|
||||
// this is usually implemented by GOTK API objects because it's used by pkg/apis/meta
|
||||
GetStatusConditions() *[]metav1.Condition
|
||||
// successMessage gives a short summary of the successful reconciliation
|
||||
successMessage() string
|
||||
}
|
||||
|
||||
func isReady(ctx context.Context, kubeClient client.Client,
|
||||
namespacedName types.NamespacedName, object statusable) wait.ConditionFunc {
|
||||
return func() (bool, error) {
|
||||
err := kubeClient.Get(ctx, namespacedName, object.asRuntimeObject())
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// Confirm the state we are observing is for the current generation
|
||||
if object.GetGeneration() != object.getObservedGeneration() {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if c := apimeta.FindStatusCondition(*object.GetStatusConditions(), meta.ReadyCondition); c != nil {
|
||||
switch c.Status {
|
||||
case metav1.ConditionTrue:
|
||||
return true, nil
|
||||
case metav1.ConditionFalse:
|
||||
return false, fmt.Errorf(c.Message)
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
Copyright 2020 The Flux authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
autov1 "github.com/fluxcd/image-automation-controller/api/v1alpha1"
|
||||
)
|
||||
|
||||
var suspendImageUpdateCmd = &cobra.Command{
|
||||
Use: "image-update [name]",
|
||||
Short: "Suspend reconciliation of an ImageUpdateAutomation",
|
||||
Long: "The suspend command disables the reconciliation of a ImageUpdateAutomation resource.",
|
||||
Example: ` # Suspend reconciliation for an existing ImageUpdateAutomation
|
||||
flux suspend auto image-update latest-images
|
||||
`,
|
||||
RunE: suspendCommand{
|
||||
humanKind: "image update automation",
|
||||
object: imageUpdateAutomationAdapter{&autov1.ImageUpdateAutomation{}},
|
||||
}.run,
|
||||
}
|
||||
|
||||
func init() {
|
||||
suspendAutoCmd.AddCommand(suspendImageUpdateCmd)
|
||||
}
|
||||
|
||||
func (update imageUpdateAutomationAdapter) isSuspended() bool {
|
||||
return update.ImageUpdateAutomation.Spec.Suspend
|
||||
}
|
||||
|
||||
func (update imageUpdateAutomationAdapter) setSuspended() {
|
||||
update.ImageUpdateAutomation.Spec.Suspend = true
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
## flux reconcile auto image-update
|
||||
|
||||
Reconcile an ImageUpdateAutomation
|
||||
|
||||
### Synopsis
|
||||
|
||||
The reconcile auto image-update command triggers a reconciliation of an ImageUpdateAutomation resource and waits for it to finish.
|
||||
|
||||
```
|
||||
flux reconcile auto image-update [name] [flags]
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
||||
```
|
||||
# Trigger an automation run for an existing image update automation
|
||||
flux reconcile auto image-update latest-images
|
||||
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
```
|
||||
-h, --help help for image-update
|
||||
```
|
||||
|
||||
### Options inherited from parent commands
|
||||
|
||||
```
|
||||
--context string kubernetes context to use
|
||||
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
||||
-n, --namespace string the namespace scope for this operation (default "flux-system")
|
||||
--timeout duration timeout for this operation (default 5m0s)
|
||||
--verbose print generated objects
|
||||
```
|
||||
|
||||
### SEE ALSO
|
||||
|
||||
* [flux reconcile auto](flux_reconcile_auto.md) - Reconcile automation objects
|
||||
|
@ -0,0 +1,40 @@
|
||||
## flux resume auto image-update
|
||||
|
||||
Resume a suspended ImageUpdateAutomation
|
||||
|
||||
### Synopsis
|
||||
|
||||
The resume command marks a previously suspended ImageUpdateAutomation resource for reconciliation and waits for it to finish.
|
||||
|
||||
```
|
||||
flux resume auto image-update [name] [flags]
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
||||
```
|
||||
# Resume reconciliation for an existing ImageUpdateAutomation
|
||||
flux resume auto image-update latest-images
|
||||
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
```
|
||||
-h, --help help for image-update
|
||||
```
|
||||
|
||||
### Options inherited from parent commands
|
||||
|
||||
```
|
||||
--context string kubernetes context to use
|
||||
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
||||
-n, --namespace string the namespace scope for this operation (default "flux-system")
|
||||
--timeout duration timeout for this operation (default 5m0s)
|
||||
--verbose print generated objects
|
||||
```
|
||||
|
||||
### SEE ALSO
|
||||
|
||||
* [flux resume auto](flux_resume_auto.md) - Resume automation objects
|
||||
|
@ -0,0 +1,40 @@
|
||||
## flux suspend auto image-update
|
||||
|
||||
Suspend reconciliation of an ImageUpdateAutomation
|
||||
|
||||
### Synopsis
|
||||
|
||||
The suspend command disables the reconciliation of a ImageUpdateAutomation resource.
|
||||
|
||||
```
|
||||
flux suspend auto image-update [name] [flags]
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
||||
```
|
||||
# Suspend reconciliation for an existing ImageUpdateAutomation
|
||||
flux suspend auto image-update latest-images
|
||||
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
```
|
||||
-h, --help help for image-update
|
||||
```
|
||||
|
||||
### Options inherited from parent commands
|
||||
|
||||
```
|
||||
--context string kubernetes context to use
|
||||
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
||||
-n, --namespace string the namespace scope for this operation (default "flux-system")
|
||||
--timeout duration timeout for this operation (default 5m0s)
|
||||
--verbose print generated objects
|
||||
```
|
||||
|
||||
### SEE ALSO
|
||||
|
||||
* [flux suspend auto](flux_suspend_auto.md) - Suspend automation objects
|
||||
|
Loading…
Reference in New Issue