Skip to content
Commits on Source (12)
......@@ -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 {
......
......@@ -40,13 +40,15 @@ flux diff kustomization my-app --path ./path/to/local/manifests`,
}
type diffKsFlags struct {
path string
path string
progressBar bool
}
var diffKsArgs diffKsFlags
func init() {
diffKsCmd.Flags().StringVar(&diffKsArgs.path, "path", "", "Path to a local directory that matches the specified Kustomization.spec.path.)")
diffKsCmd.Flags().BoolVar(&diffKsArgs.progressBar, "progress-bar", true, "Boolean to set the progress bar. The default value is true.")
diffCmd.AddCommand(diffKsCmd)
}
......@@ -64,7 +66,14 @@ func diffKsCmdRun(cmd *cobra.Command, args []string) error {
return &RequestError{StatusCode: 2, Err: fmt.Errorf("invalid resource path %q", diffKsArgs.path)}
}
builder, err := build.NewBuilder(kubeconfigArgs, name, diffKsArgs.path, build.WithTimeout(rootArgs.timeout))
var builder *build.Builder
var err error
if diffKsArgs.progressBar {
builder, err = build.NewBuilder(kubeconfigArgs, name, diffKsArgs.path, build.WithTimeout(rootArgs.timeout), build.WithProgressBar())
} else {
builder, err = build.NewBuilder(kubeconfigArgs, name, diffKsArgs.path, build.WithTimeout(rootArgs.timeout))
}
if err != nil {
return &RequestError{StatusCode: 2, Err: err}
}
......
......@@ -45,51 +45,51 @@ func TestDiffKustomization(t *testing.T) {
},
{
name: "diff nothing deployed",
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo",
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo --progress-bar=false",
objectFile: "",
assert: assertGoldenFile("./testdata/diff-kustomization/nothing-is-deployed.golden"),
},
{
name: "diff with a deployment object",
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo",
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo --progress-bar=false",
objectFile: "./testdata/diff-kustomization/deployment.yaml",
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-deployment.golden"),
},
{
name: "diff with a drifted service object",
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo",
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo --progress-bar=false",
objectFile: "./testdata/diff-kustomization/service.yaml",
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-drifted-service.golden"),
},
{
name: "diff with a drifted secret object",
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo",
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo --progress-bar=false",
objectFile: "./testdata/diff-kustomization/secret.yaml",
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-drifted-secret.golden"),
},
{
name: "diff with a drifted key in sops secret object",
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo",
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo --progress-bar=false",
objectFile: "./testdata/diff-kustomization/key-sops-secret.yaml",
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-drifted-key-sops-secret.golden"),
},
{
name: "diff with a drifted value in sops secret object",
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo",
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo --progress-bar=false",
objectFile: "./testdata/diff-kustomization/value-sops-secret.yaml",
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-drifted-value-sops-secret.golden"),
},
{
name: "diff with a sops dockerconfigjson secret object",
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo",
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo --progress-bar=false",
objectFile: "./testdata/diff-kustomization/dockerconfigjson-sops-secret.yaml",
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-dockerconfigjson-sops-secret.golden"),
},
{
name: "diff with a sops stringdata secret object",
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo",
args: "diff kustomization podinfo --path ./testdata/build-kustomization/podinfo --progress-bar=false",
objectFile: "./testdata/diff-kustomization/stringdata-sops-secret.yaml",
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-stringdata-sops-secret.golden"),
assert: assertGoldenFile("./testdata/diff-kustomization/diff-with-drifted-stringdata-sops-secret.golden"),
},
}
......@@ -137,5 +137,9 @@ func createObjectFromFile(objectFile string, templateValues map[string]string, t
t.Fatalf("Error decoding yaml file '%s': %v", objectFile, err)
}
if err := ssa.SetNativeKindsDefaults(clientObjects); err != nil {
t.Fatalf("Error setting native kinds defaults for '%s': %v", objectFile, err)
}
return clientObjects
}
......@@ -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)
......
......@@ -35,7 +35,8 @@ var resumeCmd = &cobra.Command{
}
type ResumeFlags struct {
all bool
all bool
wait bool
}
var resumeArgs ResumeFlags
......@@ -43,6 +44,8 @@ var resumeArgs ResumeFlags
func init() {
resumeCmd.PersistentFlags().BoolVarP(&resumeArgs.all, "all", "", false,
"resume all resources in that namespace")
resumeCmd.PersistentFlags().BoolVarP(&resumeArgs.wait, "wait", "", false,
"waits for one resource to reconcile before moving to the next one")
rootCmd.AddCommand(resumeCmd)
}
......@@ -107,19 +110,21 @@ func (resume resumeCommand) run(cmd *cobra.Command, args []string) error {
logger.Successf("%s resumed", resume.humanKind)
namespacedName := types.NamespacedName{
Name: resume.list.resumeItem(i).asClientObject().GetName(),
Namespace: *kubeconfigArgs.Namespace,
if resumeArgs.wait || !resumeArgs.all {
namespacedName := types.NamespacedName{
Name: resume.list.resumeItem(i).asClientObject().GetName(),
Namespace: *kubeconfigArgs.Namespace,
}
logger.Waitingf("waiting for %s reconciliation", resume.kind)
if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
isReady(ctx, kubeClient, namespacedName, resume.list.resumeItem(i))); err != nil {
logger.Failuref(err.Error())
continue
}
logger.Successf("%s reconciliation completed", resume.kind)
logger.Successf(resume.list.resumeItem(i).successMessage())
}
logger.Waitingf("waiting for %s reconciliation", resume.kind)
if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
isReady(ctx, kubeClient, namespacedName, resume.list.resumeItem(i))); err != nil {
logger.Failuref(err.Error())
continue
}
logger.Successf("%s reconciliation completed", resume.kind)
logger.Successf(resume.list.resumeItem(i).successMessage())
}
return nil
......
......@@ -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 {
......
......@@ -143,8 +143,8 @@ metadata:
name: secret-basic-auth-stringdata
namespace: default
stringData:
password: KipTT1BTKio=
username: KipTT1BTKio=
password: '**SOPS**'
username: '**SOPS**'
type: kubernetes.io/basic-auth
---
apiVersion: v1
......
......@@ -2,5 +2,11 @@
► HorizontalPodAutoscaler/default/podinfo created
► Service/default/podinfo created
► Secret/default/docker-secret created
► Secret/default/secret-basic-auth-stringdata drifted
data
- one map entry removed: + one map entry added:
username1: "*****" username: "*****"
► Secret/default/podinfo-token-77t89m9b67 created
► Secret/default/db-user-pass-bkbd782d2c created
......@@ -8,5 +8,5 @@ metadata:
namespace: default
stringData:
password: KipTT1BTKio=
username: KipTT1BTKio=
username1: KipTT1BTKio=
type: kubernetes.io/basic-auth
► deleting helmreleases thrfg in {{ .ns }} namespace
✔ helmreleases deleted
► deleting helmrelease thrfg in {{ .ns }} namespace
✔ helmrelease deleted
► 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
► suspending helmreleases thrfg in {{ .ns }} namespace
✔ helmreleases suspended
► suspending helmrelease thrfg in {{ .ns }} namespace
✔ helmrelease suspended
► deleting kustomizations tkfg in {{ .ns }} namespace
✔ kustomizations deleted
► deleting kustomization tkfg in {{ .ns }} namespace
✔ kustomization deleted