mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-10 01:37:29 +00:00
Merge pull request #2448 from SomtochiAma/metadata-client
Use `metadata.Client` for reconcile operations
This commit is contained in:
commit
b4118b73ed
16 changed files with 65 additions and 45 deletions
|
|
@ -25,8 +25,9 @@ import (
|
|||
// notificationv1.Alert
|
||||
|
||||
var alertType = apiType{
|
||||
kind: notificationv1.AlertKind,
|
||||
humanKind: "alert",
|
||||
kind: notificationv1.AlertKind,
|
||||
humanKind: "alert",
|
||||
groupVersion: notificationv1.GroupVersion,
|
||||
}
|
||||
|
||||
type alertAdapter struct {
|
||||
|
|
|
|||
|
|
@ -25,8 +25,9 @@ import (
|
|||
// notificationv1.Provider
|
||||
|
||||
var alertProviderType = apiType{
|
||||
kind: notificationv1.ProviderKind,
|
||||
humanKind: "alert provider",
|
||||
kind: notificationv1.ProviderKind,
|
||||
humanKind: "alert provider",
|
||||
groupVersion: notificationv1.GroupVersion,
|
||||
}
|
||||
|
||||
type alertProviderAdapter struct {
|
||||
|
|
|
|||
|
|
@ -25,8 +25,9 @@ import (
|
|||
// helmv2.HelmRelease
|
||||
|
||||
var helmReleaseType = apiType{
|
||||
kind: helmv2.HelmReleaseKind,
|
||||
humanKind: "helmreleases",
|
||||
kind: helmv2.HelmReleaseKind,
|
||||
humanKind: "helmrelease",
|
||||
groupVersion: helmv2.GroupVersion,
|
||||
}
|
||||
|
||||
type helmReleaseAdapter struct {
|
||||
|
|
|
|||
|
|
@ -30,8 +30,9 @@ import (
|
|||
// imagev1.ImageRepository
|
||||
|
||||
var imageRepositoryType = apiType{
|
||||
kind: imagev1.ImageRepositoryKind,
|
||||
humanKind: "image repository",
|
||||
kind: imagev1.ImageRepositoryKind,
|
||||
humanKind: "image repository",
|
||||
groupVersion: imagev1.GroupVersion,
|
||||
}
|
||||
|
||||
type imageRepositoryAdapter struct {
|
||||
|
|
@ -63,8 +64,9 @@ func (a imageRepositoryListAdapter) len() int {
|
|||
// imagev1.ImagePolicy
|
||||
|
||||
var imagePolicyType = apiType{
|
||||
kind: imagev1.ImagePolicyKind,
|
||||
humanKind: "image policy",
|
||||
kind: imagev1.ImagePolicyKind,
|
||||
humanKind: "image policy",
|
||||
groupVersion: imagev1.GroupVersion,
|
||||
}
|
||||
|
||||
type imagePolicyAdapter struct {
|
||||
|
|
@ -92,8 +94,9 @@ func (a imagePolicyListAdapter) len() int {
|
|||
// autov1.ImageUpdateAutomation
|
||||
|
||||
var imageUpdateAutomationType = apiType{
|
||||
kind: autov1.ImageUpdateAutomationKind,
|
||||
humanKind: "image update automation",
|
||||
kind: autov1.ImageUpdateAutomationKind,
|
||||
humanKind: "image update automation",
|
||||
groupVersion: autov1.GroupVersion,
|
||||
}
|
||||
|
||||
type imageUpdateAutomationAdapter struct {
|
||||
|
|
|
|||
|
|
@ -25,8 +25,9 @@ import (
|
|||
// kustomizev1.Kustomization
|
||||
|
||||
var kustomizationType = apiType{
|
||||
kind: kustomizev1.KustomizationKind,
|
||||
humanKind: "kustomizations",
|
||||
kind: kustomizev1.KustomizationKind,
|
||||
humanKind: "kustomization",
|
||||
groupVersion: kustomizev1.GroupVersion,
|
||||
}
|
||||
|
||||
type kustomizationAdapter struct {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import (
|
|||
// implementation can pick whichever it wants to use.
|
||||
type apiType struct {
|
||||
kind, humanKind string
|
||||
groupVersion schema.GroupVersion
|
||||
}
|
||||
|
||||
// adapter is an interface for a wrapper or alias from which we can
|
||||
|
|
|
|||
|
|
@ -25,8 +25,9 @@ import (
|
|||
// notificationv1.Receiver
|
||||
|
||||
var receiverType = apiType{
|
||||
kind: notificationv1.ReceiverKind,
|
||||
humanKind: "receiver",
|
||||
kind: notificationv1.ReceiverKind,
|
||||
humanKind: "receiver",
|
||||
groupVersion: notificationv1.GroupVersion,
|
||||
}
|
||||
|
||||
type receiverAdapter struct {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
apimeta "k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/client-go/util/retry"
|
||||
|
|
@ -95,7 +96,8 @@ func (reconcile reconcileCommand) run(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
|
||||
logger.Actionf("annotating %s %s in %s namespace", reconcile.kind, name, *kubeconfigArgs.Namespace)
|
||||
if err := requestReconciliation(ctx, kubeClient, namespacedName, reconcile.object); err != nil {
|
||||
if err := requestReconciliation(ctx, kubeClient, namespacedName,
|
||||
reconcile.groupVersion.WithKind(reconcile.kind)); err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Successf("%s annotated", reconcile.kind)
|
||||
|
|
@ -142,21 +144,25 @@ func reconciliationHandled(ctx context.Context, kubeClient client.Client,
|
|||
}
|
||||
|
||||
func requestReconciliation(ctx context.Context, kubeClient client.Client,
|
||||
namespacedName types.NamespacedName, obj reconcilable) error {
|
||||
namespacedName types.NamespacedName, gvk schema.GroupVersionKind) error {
|
||||
return retry.RetryOnConflict(retry.DefaultBackoff, func() (err error) {
|
||||
if err := kubeClient.Get(ctx, namespacedName, obj.asClientObject()); err != nil {
|
||||
object := &metav1.PartialObjectMetadata{}
|
||||
object.SetGroupVersionKind(gvk)
|
||||
object.SetName(namespacedName.Name)
|
||||
object.SetNamespace(namespacedName.Namespace)
|
||||
if err := kubeClient.Get(ctx, namespacedName, object); err != nil {
|
||||
return err
|
||||
}
|
||||
patch := client.MergeFrom(obj.deepCopyClientObject())
|
||||
if ann := obj.GetAnnotations(); ann == nil {
|
||||
obj.SetAnnotations(map[string]string{
|
||||
patch := client.MergeFrom(object.DeepCopy())
|
||||
if ann := object.GetAnnotations(); ann == nil {
|
||||
object.SetAnnotations(map[string]string{
|
||||
meta.ReconcileRequestAnnotation: time.Now().Format(time.RFC3339Nano),
|
||||
})
|
||||
} else {
|
||||
ann[meta.ReconcileRequestAnnotation] = time.Now().Format(time.RFC3339Nano)
|
||||
obj.SetAnnotations(ann)
|
||||
object.SetAnnotations(ann)
|
||||
}
|
||||
return kubeClient.Patch(ctx, obj.asClientObject(), patch)
|
||||
return kubeClient.Patch(ctx, object, patch)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,8 @@ func (reconcile reconcileWithSourceCommand) run(cmd *cobra.Command, args []strin
|
|||
|
||||
lastHandledReconcileAt := reconcile.object.lastHandledReconcileRequest()
|
||||
logger.Actionf("annotating %s %s in %s namespace", reconcile.kind, name, *kubeconfigArgs.Namespace)
|
||||
if err := requestReconciliation(ctx, kubeClient, namespacedName, reconcile.object); err != nil {
|
||||
if err := requestReconciliation(ctx, kubeClient, namespacedName,
|
||||
reconcile.groupVersion.WithKind(reconcile.kind)); err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Successf("%s annotated", reconcile.kind)
|
||||
|
|
|
|||
|
|
@ -29,8 +29,9 @@ import (
|
|||
// sourcev1.Bucket
|
||||
|
||||
var bucketType = apiType{
|
||||
kind: sourcev1.BucketKind,
|
||||
humanKind: "source bucket",
|
||||
kind: sourcev1.BucketKind,
|
||||
humanKind: "source bucket",
|
||||
groupVersion: sourcev1.GroupVersion,
|
||||
}
|
||||
|
||||
type bucketAdapter struct {
|
||||
|
|
@ -62,8 +63,9 @@ func (a bucketListAdapter) len() int {
|
|||
// sourcev1.HelmChart
|
||||
|
||||
var helmChartType = apiType{
|
||||
kind: sourcev1.HelmChartKind,
|
||||
humanKind: "source chart",
|
||||
kind: sourcev1.HelmChartKind,
|
||||
humanKind: "source chart",
|
||||
groupVersion: sourcev1.GroupVersion,
|
||||
}
|
||||
|
||||
type helmChartAdapter struct {
|
||||
|
|
@ -95,8 +97,9 @@ func (a helmChartListAdapter) len() int {
|
|||
// sourcev1.GitRepository
|
||||
|
||||
var gitRepositoryType = apiType{
|
||||
kind: sourcev1.GitRepositoryKind,
|
||||
humanKind: "source git",
|
||||
kind: sourcev1.GitRepositoryKind,
|
||||
humanKind: "source git",
|
||||
groupVersion: sourcev1.GroupVersion,
|
||||
}
|
||||
|
||||
type gitRepositoryAdapter struct {
|
||||
|
|
@ -128,8 +131,9 @@ func (a gitRepositoryListAdapter) len() int {
|
|||
// sourcev1.HelmRepository
|
||||
|
||||
var helmRepositoryType = apiType{
|
||||
kind: sourcev1.HelmRepositoryKind,
|
||||
humanKind: "source helm",
|
||||
kind: sourcev1.HelmRepositoryKind,
|
||||
humanKind: "source helm",
|
||||
groupVersion: sourcev1.GroupVersion,
|
||||
}
|
||||
|
||||
type helmRepositoryAdapter struct {
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
► deleting helmreleases thrfg in {{ .ns }} namespace
|
||||
✔ helmreleases deleted
|
||||
► deleting helmrelease thrfg in {{ .ns }} namespace
|
||||
✔ helmrelease deleted
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
► resuming helmreleases thrfg in {{ .ns }} namespace
|
||||
✔ helmreleases resumed
|
||||
► resuming helmrelease thrfg in {{ .ns }} namespace
|
||||
✔ helmrelease resumed
|
||||
◎ waiting for HelmRelease reconciliation
|
||||
✔ HelmRelease reconciliation completed
|
||||
✔ applied revision 6.0.0
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
► suspending helmreleases thrfg in {{ .ns }} namespace
|
||||
✔ helmreleases suspended
|
||||
► suspending helmrelease thrfg in {{ .ns }} namespace
|
||||
✔ helmrelease suspended
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
► deleting kustomizations tkfg in {{ .ns }} namespace
|
||||
✔ kustomizations deleted
|
||||
► deleting kustomization tkfg in {{ .ns }} namespace
|
||||
✔ kustomization deleted
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
► resuming kustomizations tkfg in {{ .ns }} namespace
|
||||
✔ kustomizations resumed
|
||||
► resuming kustomization tkfg in {{ .ns }} namespace
|
||||
✔ kustomization resumed
|
||||
◎ waiting for Kustomization reconciliation
|
||||
✔ Kustomization reconciliation completed
|
||||
✔ applied revision 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
► suspending kustomizations tkfg in {{ .ns }} namespace
|
||||
✔ kustomizations suspended
|
||||
► suspending kustomization tkfg in {{ .ns }} namespace
|
||||
✔ kustomization suspended
|
||||
|
|
|
|||
Loading…
Reference in a new issue