Skip to content

Commit

Permalink
cleaner import statements
Browse files Browse the repository at this point in the history
  • Loading branch information
manedurphy committed Aug 22, 2021
1 parent d8a6fb0 commit 8888b56
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 38 deletions.
35 changes: 15 additions & 20 deletions controllers/secretproviderclasspodstatus_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,29 @@ import (
"sync"
"time"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/secrets-store-csi-driver/pkg/util/spcutil"

"sigs.k8s.io/controller-runtime/pkg/manager"

"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"

"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/secrets-store-csi-driver/apis/v1alpha1"
"sigs.k8s.io/secrets-store-csi-driver/pkg/client/clientset/versioned/scheme"
"sigs.k8s.io/secrets-store-csi-driver/pkg/util/fileutil"
"sigs.k8s.io/secrets-store-csi-driver/pkg/util/k8sutil"
"sigs.k8s.io/secrets-store-csi-driver/pkg/util/secretutil"

ctrl "sigs.k8s.io/controller-runtime"
client "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/secrets-store-csi-driver/pkg/util/spcutil"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
clientcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
ctrl "sigs.k8s.io/controller-runtime"
client "sigs.k8s.io/controller-runtime/pkg/client"
)

const (
Expand Down Expand Up @@ -172,7 +167,7 @@ func (r *SecretProviderClassPodStatusReconciler) Patcher(ctx context.Context) er
if spc.Spec.SyncOptions.SyncAll {
files, err := fileutil.GetMountedFiles(spcPodStatus.Status.TargetPath)
if err != nil {
klog.ErrorS(err, "failed to get mounted files", "spc", klog.KObj(spc), "pod", klog.KObj(pod), "spcps", klog.KObj(&spcPodStatus))
return fmt.Errorf("failed to get mounted files for pod %s/%s: %v", namespace, pod.Name, err)
} else {
if len(spc.Spec.SecretObjects) == 0 {
spc.Spec.SecretObjects = spcutil.BuildSecretObjects(files, secretutil.GetSecretType(strings.TrimSpace(spc.Spec.SyncOptions.Type)))
Expand Down Expand Up @@ -299,6 +294,11 @@ func (r *SecretProviderClassPodStatusReconciler) Reconcile(ctx context.Context,
}

files, err := fileutil.GetMountedFiles(spcPodStatus.Status.TargetPath)
if err != nil {
r.generateEvent(pod, corev1.EventTypeWarning, secretCreationFailedReason, fmt.Sprintf("failed to get mounted files, err: %+v", err))
klog.ErrorS(err, "failed to get mounted files", "spc", klog.KObj(spc), "pod", klog.KObj(pod), "spcps", klog.KObj(spcPodStatus))
return ctrl.Result{RequeueAfter: 10 * time.Second}, err
}

if spc.Spec.SyncOptions.SyncAll {
if len(spc.Spec.SecretObjects) == 0 {
Expand All @@ -318,11 +318,6 @@ func (r *SecretProviderClassPodStatusReconciler) Reconcile(ctx context.Context,
}
}

if err != nil {
r.generateEvent(pod, corev1.EventTypeWarning, secretCreationFailedReason, fmt.Sprintf("failed to get mounted files, err: %+v", err))
klog.ErrorS(err, "failed to get mounted files", "spc", klog.KObj(spc), "pod", klog.KObj(pod), "spcps", klog.KObj(spcPodStatus))
return ctrl.Result{RequeueAfter: 10 * time.Second}, err
}
errs := make([]error, 0)
for _, secretObj := range spc.Spec.SecretObjects {
secretName := strings.TrimSpace(secretObj.SecretName)
Expand Down
31 changes: 14 additions & 17 deletions pkg/rotation/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,10 @@ import (
"strings"
"time"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/strategicpatch"
clientcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"

v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/wait"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
Expand All @@ -42,19 +36,22 @@ import (
"k8s.io/client-go/util/workqueue"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"

"sigs.k8s.io/secrets-store-csi-driver/apis/v1alpha1"
"sigs.k8s.io/secrets-store-csi-driver/controllers"
"sigs.k8s.io/secrets-store-csi-driver/pkg/client/clientset/versioned"
secretsStoreClient "sigs.k8s.io/secrets-store-csi-driver/pkg/client/clientset/versioned"
internalerrors "sigs.k8s.io/secrets-store-csi-driver/pkg/errors"
"sigs.k8s.io/secrets-store-csi-driver/pkg/k8s"
secretsstore "sigs.k8s.io/secrets-store-csi-driver/pkg/secrets-store"
"sigs.k8s.io/secrets-store-csi-driver/pkg/util/fileutil"
"sigs.k8s.io/secrets-store-csi-driver/pkg/util/k8sutil"
"sigs.k8s.io/secrets-store-csi-driver/pkg/util/secretutil"
"sigs.k8s.io/secrets-store-csi-driver/pkg/util/spcutil"
"sigs.k8s.io/secrets-store-csi-driver/pkg/version"

v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientcorev1 "k8s.io/client-go/kubernetes/typed/core/v1"
secretsStoreClient "sigs.k8s.io/secrets-store-csi-driver/pkg/client/clientset/versioned"
internalerrors "sigs.k8s.io/secrets-store-csi-driver/pkg/errors"
secretsstore "sigs.k8s.io/secrets-store-csi-driver/pkg/secrets-store"
)

const (
Expand Down Expand Up @@ -82,7 +79,7 @@ type Reconciler struct {
reporter StatsReporter
eventRecorder record.EventRecorder
kubeClient kubernetes.Interface
crdClient versioned.Interface
crdClient secretsStoreClient.Interface
// cache contains v1.Pod, v1alpha1.SecretProviderClassPodStatus (both filtered on *nodeID),
// v1.Secret (filtered on secrets-store.csi.k8s.io/managed=true)
cache client.Reader
Expand Down Expand Up @@ -435,6 +432,10 @@ func (r *Reconciler) reconcile(ctx context.Context, spcps *v1alpha1.SecretProvid
}

files, err := fileutil.GetMountedFiles(spcps.Status.TargetPath)
if err != nil {
r.generateEvent(pod, v1.EventTypeWarning, k8sSecretRotationFailedReason, fmt.Sprintf("failed to get mounted files, err: %+v", err))
return fmt.Errorf("failed to get mounted files, err: %+v", err)
}

if spc.Spec.SyncOptions.SyncAll {
if len(spc.Spec.SecretObjects) == 0 {
Expand All @@ -454,10 +455,6 @@ func (r *Reconciler) reconcile(ctx context.Context, spcps *v1alpha1.SecretProvid
}
}

if err != nil {
r.generateEvent(pod, v1.EventTypeWarning, k8sSecretRotationFailedReason, fmt.Sprintf("failed to get mounted files, err: %+v", err))
return fmt.Errorf("failed to get mounted files, err: %+v", err)
}
for _, secretObj := range spc.Spec.SecretObjects {
secretName := strings.TrimSpace(secretObj.SecretName)

Expand Down
3 changes: 2 additions & 1 deletion pkg/util/spcutil/secret_object_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package spcutil
import (
"strings"

corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/secrets-store-csi-driver/apis/v1alpha1"

corev1 "k8s.io/api/core/v1"
)

const (
Expand Down

0 comments on commit 8888b56

Please sign in to comment.