Skip to content

Commit

Permalink
refactor: cleanup imports
Browse files Browse the repository at this point in the history
Signed-off-by: Chin-Ya Huang <chin-ya.huang@suse.com>
(cherry picked from commit aef3226)
  • Loading branch information
c3y1huang authored and David Ko committed Aug 23, 2023
1 parent c0f4cd9 commit e15bd1e
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 41 deletions.
4 changes: 2 additions & 2 deletions app/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/longhorn/longhorn-manager/upgrade"
"github.com/longhorn/longhorn-manager/util"

metricsCollector "github.com/longhorn/longhorn-manager/metrics_collector"
metricscollector "github.com/longhorn/longhorn-manager/metrics_collector"
)

const (
Expand Down Expand Up @@ -164,7 +164,7 @@ func startManager(c *cli.Context) error {

m := manager.NewVolumeManager(currentNodeID, ds, proxyConnCounter)

metricsCollector.InitMetricsCollectorSystem(logger, currentNodeID, ds, kubeconfigPath, proxyConnCounter)
metricscollector.InitMetricsCollectorSystem(logger, currentNodeID, ds, kubeconfigPath, proxyConnCounter)

defaultImageSettings := map[types.SettingName]string{
types.SettingNameDefaultEngineImage: engineImage,
Expand Down
14 changes: 7 additions & 7 deletions app/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/version"
"k8s.io/client-go/tools/clientcmd"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/version"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"

"github.com/longhorn/longhorn-manager/csi"
"github.com/longhorn/longhorn-manager/types"
Expand Down Expand Up @@ -252,14 +252,14 @@ func deployCSIDriver(kubeClient *clientset.Clientset, lhClient *lhclientset.Clie
return err
}

var imagePullPolicy v1.PullPolicy
var imagePullPolicy corev1.PullPolicy
switch imagePullPolicySetting.Value {
case string(types.SystemManagedPodsImagePullPolicyNever):
imagePullPolicy = v1.PullNever
imagePullPolicy = corev1.PullNever
case string(types.SystemManagedPodsImagePullPolicyIfNotPresent):
imagePullPolicy = v1.PullIfNotPresent
imagePullPolicy = corev1.PullIfNotPresent
case string(types.SystemManagedPodsImagePullPolicyAlways):
imagePullPolicy = v1.PullAlways
imagePullPolicy = corev1.PullAlways
default:
return fmt.Errorf("invalid image pull policy %v", imagePullPolicySetting.Value)
}
Expand Down
28 changes: 14 additions & 14 deletions app/get_proc_arg.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/sirupsen/logrus"

v1 "k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes"

Expand Down Expand Up @@ -52,7 +52,7 @@ const (
if [ ! -f $proc/cmdline ]; then
continue
fi
# Before k3s v1.19, the cmdline is separated by \000.
# Before k3s v1.19, the cmdline is separated by \000.
# After v1.19, it's using normal spaces, which is \040
if [[ "$(cat $proc/cmdline | tr '\000' '\n' | tr '\040' '\n' | head -n1 | tr '/' '\n' | tail -n1)" == "k3s" ]]; then
proc_name=$(cat $proc/cmdline | tr '\000' '\n' | tr '\040' '\n' | sed -n '2p')
Expand All @@ -69,7 +69,7 @@ const (
`
)

func getProcArg(kubeClient *clientset.Clientset, managerImage, serviceAccountName, name string, tolerations []v1.Toleration, priorityClass, registrySecret string, nodeSelector map[string]string) (string, error) {
func getProcArg(kubeClient *clientset.Clientset, managerImage, serviceAccountName, name string, tolerations []corev1.Toleration, priorityClass, registrySecret string, nodeSelector map[string]string) (string, error) {
switch name {
case ArgKubeletRootDir:
dir, err := detectKubeletRootDir(kubeClient, managerImage, serviceAccountName, tolerations, priorityClass, registrySecret, nodeSelector)
Expand All @@ -81,7 +81,7 @@ func getProcArg(kubeClient *clientset.Clientset, managerImage, serviceAccountNam
return "", fmt.Errorf("getting arg %v is not supported", name)
}

func detectKubeletRootDir(kubeClient *clientset.Clientset, managerImage, serviceAccountName string, tolerations []v1.Toleration, priorityClass, registrySecret string, nodeSelector map[string]string) (string, error) {
func detectKubeletRootDir(kubeClient *clientset.Clientset, managerImage, serviceAccountName string, tolerations []corev1.Toleration, priorityClass, registrySecret string, nodeSelector map[string]string) (string, error) {
// try to detect root-dir in proc kubelet
kubeletCmdline, err := getProcCmdline(kubeClient, managerImage, serviceAccountName, KubeletDetectionPodName, GetKubeletCmdlineScript, tolerations, priorityClass, registrySecret, nodeSelector)
if err != nil {
Expand Down Expand Up @@ -112,7 +112,7 @@ func detectKubeletRootDir(kubeClient *clientset.Clientset, managerImage, service
return "", fmt.Errorf("failed to get kubelet root dir, no related proc for root-dir detection, error out")
}

func getProcCmdline(kubeClient *clientset.Clientset, managerImage, serviceAccountName, name, script string, tolerations []v1.Toleration, priorityClass, registrySecret string, nodeSelector map[string]string) (string, error) {
func getProcCmdline(kubeClient *clientset.Clientset, managerImage, serviceAccountName, name, script string, tolerations []corev1.Toleration, priorityClass, registrySecret string, nodeSelector map[string]string) (string, error) {
namespace := os.Getenv(types.EnvPodNamespace)
if namespace == "" {
return "", fmt.Errorf("failed to detect pod namespace, environment variable %v is missing", types.EnvPodNamespace)
Expand All @@ -139,7 +139,7 @@ func getProcCmdline(kubeClient *clientset.Clientset, managerImage, serviceAccoun
for i := 0; i < DetectPodMaxPolls; i++ {
if pod, err := kubeClient.CoreV1().Pods(namespace).Get(context.TODO(), name, metav1.GetOptions{}); err != nil {
logrus.Warnf("failed to get proc cmdline detection pod %v: %v", name, err)
} else if pod.Status.Phase == v1.PodSucceeded {
} else if pod.Status.Phase == corev1.PodSucceeded {
completed = true
break
} else {
Expand All @@ -158,28 +158,28 @@ func getProcCmdline(kubeClient *clientset.Clientset, managerImage, serviceAccoun
return procArg, nil
}

func deployDetectionPod(kubeClient *clientset.Clientset, namespace, managerImage, serviceAccountName, name, script string, tolerations []v1.Toleration, priorityClass, registrySecret string, nodeSelector map[string]string) error {
func deployDetectionPod(kubeClient *clientset.Clientset, namespace, managerImage, serviceAccountName, name, script string, tolerations []corev1.Toleration, priorityClass, registrySecret string, nodeSelector map[string]string) error {
privileged := true
detectionPodSpec := &v1.Pod{
detectionPodSpec := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: v1.PodSpec{
Spec: corev1.PodSpec{
ServiceAccountName: serviceAccountName,
Tolerations: tolerations,
NodeSelector: nodeSelector,
Containers: []v1.Container{
Containers: []corev1.Container{
{
Name: name,
Image: managerImage,
Command: []string{"/bin/bash"},
Args: []string{"-c", script},
SecurityContext: &v1.SecurityContext{
SecurityContext: &corev1.SecurityContext{
Privileged: &privileged,
},
},
},
RestartPolicy: v1.RestartPolicyNever,
RestartPolicy: corev1.RestartPolicyNever,
HostPID: true,
},
}
Expand All @@ -189,7 +189,7 @@ func deployDetectionPod(kubeClient *clientset.Clientset, namespace, managerImage
}

if registrySecret != "" {
detectionPodSpec.Spec.ImagePullSecrets = []v1.LocalObjectReference{
detectionPodSpec.Spec.ImagePullSecrets = []corev1.LocalObjectReference{
{
Name: registrySecret,
},
Expand All @@ -202,7 +202,7 @@ func deployDetectionPod(kubeClient *clientset.Clientset, namespace, managerImage
}

func getPodLogAsString(kubeClient *clientset.Clientset, namespace, name string) (string, error) {
req := kubeClient.CoreV1().Pods(namespace).GetLogs(name, &v1.PodLogOptions{})
req := kubeClient.CoreV1().Pods(namespace).GetLogs(name, &corev1.PodLogOptions{})
if req.URL().Path == "" {
return "", fmt.Errorf("getPodLogAsString for %v/%v returns empty request path, may due to unit test run: %+v", namespace, name, req)
}
Expand Down
12 changes: 7 additions & 5 deletions app/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli"

v1 "k8s.io/api/core/v1"
"k8s.io/client-go/rest"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kubeclientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"

"github.com/longhorn/longhorn-manager/datastore"
"github.com/longhorn/longhorn-manager/types"

longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
lhclientset "github.com/longhorn/longhorn-manager/k8s/pkg/client/clientset/versioned"
"github.com/longhorn/longhorn-manager/types"
)

const (
Expand Down Expand Up @@ -148,8 +150,8 @@ func migratePVAndPVCForPre070Volume(kubeClient *kubeclientset.Clientset, lhClien
}
}()

if oldPV.Spec.PersistentVolumeReclaimPolicy != v1.PersistentVolumeReclaimRetain {
oldPV.Spec.PersistentVolumeReclaimPolicy = v1.PersistentVolumeReclaimRetain
if oldPV.Spec.PersistentVolumeReclaimPolicy != corev1.PersistentVolumeReclaimRetain {
oldPV.Spec.PersistentVolumeReclaimPolicy = corev1.PersistentVolumeReclaimRetain
if oldPV, err = kubeClient.CoreV1().PersistentVolumes().Update(context.TODO(), oldPV, metav1.UpdateOptions{}); err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion app/post_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/longhorn/longhorn-manager/types"
)

Expand Down
4 changes: 3 additions & 1 deletion app/pre_uppgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"

"k8s.io/client-go/tools/clientcmd"

lhclientset "github.com/longhorn/longhorn-manager/k8s/pkg/client/clientset/versioned"
"github.com/longhorn/longhorn-manager/types"

lhclientset "github.com/longhorn/longhorn-manager/k8s/pkg/client/clientset/versioned"
upgradeutil "github.com/longhorn/longhorn-manager/upgrade/util"
)

Expand Down
6 changes: 4 additions & 2 deletions app/recovery_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
"fmt"
"net/http"

"github.com/sirupsen/logrus"

"k8s.io/client-go/tools/clientcmd"

"github.com/longhorn/longhorn-manager/recovery_backend/server"
"github.com/longhorn/longhorn-manager/types"
"github.com/longhorn/longhorn-manager/util"
"github.com/longhorn/longhorn-manager/util/client"
"github.com/sirupsen/logrus"
"k8s.io/client-go/tools/clientcmd"
)

func startRecoveryBackend(ctx context.Context, serviceAccount, kubeconfigPath string) error {
Expand Down
15 changes: 8 additions & 7 deletions app/recurring_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"

"golang.org/x/sync/errgroup"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/record"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
clientset "k8s.io/client-go/kubernetes"
typedv1core "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/record"

longhornclient "github.com/longhorn/longhorn-manager/client"
"github.com/longhorn/longhorn-manager/constant"
longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
lhclientset "github.com/longhorn/longhorn-manager/k8s/pkg/client/clientset/versioned"
"github.com/longhorn/longhorn-manager/types"
"github.com/longhorn/longhorn-manager/util"

longhornclient "github.com/longhorn/longhorn-manager/client"
longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
lhclientset "github.com/longhorn/longhorn-manager/k8s/pkg/client/clientset/versioned"
)

const (
Expand Down
7 changes: 5 additions & 2 deletions app/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
apiextensionsclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"

"k8s.io/client-go/informers"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"

apiextensionsclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
clientset "k8s.io/client-go/kubernetes"

"github.com/longhorn/longhorn-manager/controller"
"github.com/longhorn/longhorn-manager/datastore"

lhclientset "github.com/longhorn/longhorn-manager/k8s/pkg/client/clientset/versioned"
lhinformers "github.com/longhorn/longhorn-manager/k8s/pkg/client/informers/externalversions"
)
Expand Down
1 change: 1 addition & 0 deletions app/upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/sirupsen/logrus"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes"

Expand Down
1 change: 1 addition & 0 deletions app/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/sirupsen/logrus"

"k8s.io/client-go/tools/clientcmd"

"github.com/longhorn/longhorn-manager/types"
Expand Down

0 comments on commit e15bd1e

Please sign in to comment.