Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated dependencies #498

Merged
merged 1 commit into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions controllers/kustomization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
"sigs.k8s.io/kustomize/api/filesys"
"sigs.k8s.io/kustomize/kyaml/filesys"

"github.com/fluxcd/pkg/apis/meta"
"github.com/fluxcd/pkg/runtime/events"
Expand Down Expand Up @@ -252,7 +252,7 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
// broadcast the reconciliation failure and requeue at the specified retry interval
if reconcileErr != nil {
log.Error(reconcileErr, fmt.Sprintf("Reconciliation failed after %s, next try in %s",
time.Now().Sub(reconcileStart).String(),
time.Since(reconcileStart).String(),
kustomization.GetRetryInterval().String()),
"revision",
source.GetArtifact().Revision)
Expand All @@ -263,12 +263,9 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques

// broadcast the reconciliation result and requeue at the specified interval
msg := fmt.Sprintf("Reconciliation finished in %s, next run in %s",
time.Now().Sub(reconcileStart).String(),
time.Since(reconcileStart).String(),
kustomization.Spec.Interval.Duration.String())
log.Info(fmt.Sprintf(msg),
"revision",
source.GetArtifact().Revision,
)
log.Info(msg, "revision", source.GetArtifact().Revision)
r.event(ctx, reconciledKustomization, source.GetArtifact().Revision, events.EventSeverityInfo,
msg, map[string]string{"commit_status": "update"})
return ctrl.Result{RequeueAfter: kustomization.Spec.Interval.Duration}, nil
Expand Down Expand Up @@ -606,10 +603,6 @@ func (r *KustomizationReconciler) generate(kustomization kustomizev1.Kustomizati
}

func (r *KustomizationReconciler) build(ctx context.Context, kustomization kustomizev1.Kustomization, dirPath string) ([]byte, error) {
timeout := kustomization.GetTimeout()
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

dec, cleanup, err := NewTempDecryptor(r.Client, kustomization)
if err != nil {
return nil, err
Expand Down Expand Up @@ -809,13 +802,13 @@ func (r *KustomizationReconciler) checkHealth(ctx context.Context, manager *ssa.
Interval: 5 * time.Second,
Timeout: kustomization.GetTimeout(),
}); err != nil {
return fmt.Errorf("Health check failed after %s, %w", time.Now().Sub(checkStart).String(), err)
return fmt.Errorf("Health check failed after %s, %w", time.Since(checkStart).String(), err)
}

// emit event if the previous health check failed
if !wasHealthy || (kustomization.Status.LastAppliedRevision != revision && drifted) {
r.event(ctx, kustomization, revision, events.EventSeverityInfo,
fmt.Sprintf("Health check passed in %s", time.Now().Sub(checkStart).String()), nil)
fmt.Sprintf("Health check passed in %s", time.Since(checkStart).String()), nil)
}

return nil
Expand Down Expand Up @@ -858,7 +851,7 @@ func (r *KustomizationReconciler) finalize(ctx context.Context, kustomization ku
!kustomization.Spec.Suspend &&
kustomization.Status.Inventory != nil &&
kustomization.Status.Inventory.Entries != nil {
objects, err := ListObjectsInInventory(kustomization.Status.Inventory)
objects, _ := ListObjectsInInventory(kustomization.Status.Inventory)

impersonation := NewKustomizeImpersonation(kustomization, r.Client, r.StatusPoller, "")
kubeClient, _, err := impersonation.GetClient(ctx)
Expand Down
1 change: 1 addition & 0 deletions controllers/kustomization_force_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ stringData:
}

artifact, err := testServer.ArtifactFromFiles(manifests(id, randStringRunes(5)))
g.Expect(err).NotTo(HaveOccurred(), "failed to create artifact from files")

repositoryName := types.NamespacedName{
Name: fmt.Sprintf("force-%s", randStringRunes(5)),
Expand Down
2 changes: 1 addition & 1 deletion controllers/kustomization_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import (
"strings"
"sync"

"sigs.k8s.io/kustomize/api/filesys"
"sigs.k8s.io/kustomize/api/konfig"
"sigs.k8s.io/kustomize/api/krusty"
"sigs.k8s.io/kustomize/api/provider"
"sigs.k8s.io/kustomize/api/resmap"
kustypes "sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/filesys"
"sigs.k8s.io/yaml"

kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2"
Expand Down
2 changes: 1 addition & 1 deletion controllers/kustomization_impersonation.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (ki *KustomizeImpersonation) getKubeConfig(ctx context.Context) ([]byte, er
}

var kubeConfig []byte
for k, _ := range secret.Data {
for k := range secret.Data {
if k == "value" || k == "value.yaml" {
kubeConfig = secret.Data[k]
break
Expand Down
2 changes: 1 addition & 1 deletion controllers/kustomization_indexers.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (r *KustomizationReconciler) requestsForRevisionChangeOf(indexKey string) f
if err != nil {
return nil
}
reqs := make([]reconcile.Request, len(sorted), len(sorted))
reqs := make([]reconcile.Request, len(sorted))
for i := range sorted {
reqs[i].NamespacedName.Name = sorted[i].Name
reqs[i].NamespacedName.Namespace = sorted[i].Namespace
Expand Down
8 changes: 4 additions & 4 deletions controllers/kustomization_prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,10 @@ data:
empty := []testserver.File{
{
Name: "kustomization.yaml",
Body: fmt.Sprintf(`---
Body: `---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
`),
`,
},
}
artifact, err := testServer.ArtifactFromFiles(empty)
Expand Down Expand Up @@ -400,10 +400,10 @@ data:
g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: id, Namespace: id}, resultSecret)).Should(Succeed())
g.Expect(k8sClient.Get(context.Background(), types.NamespacedName{Name: id, Namespace: id}, resultConfig)).Should(Succeed())

name, _ := resultConfig.GetLabels()["kustomize.toolkit.fluxcd.io/name"]
name := resultConfig.GetLabels()["kustomize.toolkit.fluxcd.io/name"]
g.Expect(name).Should(BeIdenticalTo(kustomizationKey.Name))

namespace, _ := resultConfig.GetLabels()["kustomize.toolkit.fluxcd.io/namespace"]
namespace := resultConfig.GetLabels()["kustomize.toolkit.fluxcd.io/namespace"]
g.Expect(namespace).Should(BeIdenticalTo(kustomizationKey.Namespace))
})

Expand Down
7 changes: 3 additions & 4 deletions controllers/kustomization_transformer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package controllers

import (
"context"
"fmt"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -55,7 +54,7 @@ func TestKustomizationReconciler_KustomizeTransformer(t *testing.T) {
g.Expect(err).ToNot(HaveOccurred())

repositoryName := types.NamespacedName{
Name: fmt.Sprintf("%s", randStringRunes(5)),
Name: randStringRunes(5),
Namespace: id,
}

Expand Down Expand Up @@ -178,7 +177,7 @@ func TestKustomizationReconciler_KustomizeTransformerFiles(t *testing.T) {
g.Expect(err).ToNot(HaveOccurred())

repositoryName := types.NamespacedName{
Name: fmt.Sprintf("%s", randStringRunes(5)),
Name: randStringRunes(5),
Namespace: id,
}

Expand Down Expand Up @@ -297,7 +296,7 @@ func TestKustomizationReconciler_FluxTransformers(t *testing.T) {
g.Expect(err).ToNot(HaveOccurred())

repositoryName := types.NamespacedName{
Name: fmt.Sprintf("%s", randStringRunes(5)),
Name: randStringRunes(5),
Namespace: id,
}

Expand Down
6 changes: 3 additions & 3 deletions controllers/kustomization_varsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ metadata:
g.Expect(err).NotTo(HaveOccurred())

repositoryName := types.NamespacedName{
Name: fmt.Sprintf("%s", randStringRunes(5)),
Name: randStringRunes(5),
Namespace: id,
}

err = applyGitRepository(repositoryName, artifact, revision)
g.Expect(err).NotTo(HaveOccurred())

configName := types.NamespacedName{
Name: fmt.Sprintf("%s", randStringRunes(5)),
Name: randStringRunes(5),
Namespace: id,
}
config := &corev1.ConfigMap{
Expand All @@ -88,7 +88,7 @@ metadata:
g.Expect(k8sClient.Create(context.Background(), config)).Should(Succeed())

secretName := types.NamespacedName{
Name: fmt.Sprintf("%s", randStringRunes(5)),
Name: randStringRunes(5),
Namespace: id,
}
secret := &corev1.Secret{
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ replace github.com/fluxcd/kustomize-controller/api => ./api

require (
filippo.io/age v1.0.0
github.com/ProtonMail/go-crypto v0.0.0-20211112122917-428f8eabeeb3
github.com/cyphar/filepath-securejoin v0.2.2
github.com/drone/envsubst v1.0.3-0.20200804185402-58bc65f69603
github.com/fluxcd/kustomize-controller/api v0.18.0
Expand All @@ -21,7 +22,6 @@ require (
github.com/onsi/gomega v1.15.0
github.com/spf13/pflag v1.0.5
go.mozilla.org/sops/v3 v3.7.1
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023
google.golang.org/grpc v1.42.0
k8s.io/api v0.22.2
Expand All @@ -31,6 +31,7 @@ require (
sigs.k8s.io/cli-utils v0.26.0
sigs.k8s.io/controller-runtime v0.10.2
sigs.k8s.io/kustomize/api v0.10.1
sigs.k8s.io/kustomize/kyaml v0.13.0
sigs.k8s.io/yaml v1.3.0
)

Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMo
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/ProtonMail/go-crypto v0.0.0-20211112122917-428f8eabeeb3 h1:XcF0cTDJeiuZ5NU8w7WUDge0HRwwNRmxj/GGk6KSA6g=
github.com/ProtonMail/go-crypto v0.0.0-20211112122917-428f8eabeeb3/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
Expand Down Expand Up @@ -807,6 +809,7 @@ golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ=
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down
6 changes: 3 additions & 3 deletions internal/sops/keyservice/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

"go.mozilla.org/sops/v3/keyservice"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/fluxcd/kustomize-controller/internal/sops/age"
"github.com/fluxcd/kustomize-controller/internal/sops/pgp"
Expand Down Expand Up @@ -126,7 +126,7 @@ func keyToString(key *keyservice.Key) string {
case *keyservice.Key_PgpKey:
return fmt.Sprintf("PGP key with fingerprint %s", k.PgpKey.Fingerprint)
default:
return fmt.Sprintf("Unknown key type")
return "Unknown key type"
}
}

Expand All @@ -141,7 +141,7 @@ func (ks Server) prompt(key *keyservice.Key, requestType string) error {
}
}
if response == "n" {
return grpc.Errorf(codes.PermissionDenied, "Request rejected by user")
return status.Errorf(codes.PermissionDenied, "Request rejected by user")
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/sops/pgp/keysource.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"strings"
"time"

"golang.org/x/crypto/openpgp"
"golang.org/x/crypto/openpgp/armor"
"github.com/ProtonMail/go-crypto/openpgp"
"github.com/ProtonMail/go-crypto/openpgp/armor"
)

// MasterKey is a PGP key used to securely store sops' data key by
Expand Down