Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #952 from kinvolk/invidian/more-cleanup
Browse files Browse the repository at this point in the history
Remove pkg/util package
  • Loading branch information
invidian authored Sep 15, 2020
2 parents 2e1ac51 + 5ca727b commit 9033e47
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 176 deletions.
29 changes: 25 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package config
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/hashicorp/hcl/v2"
Expand All @@ -25,8 +26,6 @@ import (
"github.com/mitchellh/go-homedir"
"github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/function"

"github.com/kinvolk/lokomotive/pkg/util"
)

type variable struct {
Expand Down Expand Up @@ -62,7 +61,7 @@ type Config struct {
}

func loadLokocfgPaths(configPath string) ([]string, error) {
isDir, err := util.PathIsDir(configPath)
isDir, err := pathIsDir(configPath)
if err != nil {
return nil, fmt.Errorf("failed to stat config path %q: %w", configPath, err)
}
Expand Down Expand Up @@ -104,7 +103,7 @@ func LoadConfig(lokocfgPath, lokocfgVarsPath string) (*Config, hcl.Diagnostics)

configBody := hcl.MergeFiles(hclFiles)

exists, err := util.PathExists(lokocfgVarsPath)
exists, err := pathExists(lokocfgVarsPath)
if err != nil {
return nil, hcl.Diagnostics{
&hcl.Diagnostic{
Expand Down Expand Up @@ -205,3 +204,25 @@ func (c *Config) LoadComponentConfigBody(componentName string) *hcl.Body {
}
return nil
}

func pathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}

if os.IsNotExist(err) {
return false, nil
}

return true, err
}

func pathIsDir(path string) (bool, error) {
stat, err := os.Stat(path)
if err == nil {
return stat.IsDir(), nil
}

return false, err
}
27 changes: 13 additions & 14 deletions pkg/lokomotive/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@ import (
"time"

v1 "k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"

"github.com/kinvolk/lokomotive/pkg/util/retryutil"
)

const (
// Max number of retries when waiting for cluster to become available.
clusterPingRetries = 18
// Period after which we assume cluster will not become reachable and we return timeout error to the user.
clusterPingRetryTimeout = 5 * time.Minute
// Number of seconds to wait between retires when waiting for cluster to become available.
clusterPingRetryInterval = 10
// Max number of retries when waiting for nodes to become ready.
nodeReadinessRetries = 18
clusterPingRetryInterval = 10 * time.Second
// Period after which we assume that nodes will never become ready and we return timeout error to the user.
nodeReadinessRetryTimeout = 10 * time.Minute
// Number of seconds to wait between retires when waiting for nodes to become ready.
nodeReadinessRetryInterval = 10
nodeReadinessRetryInterval = 10 * time.Second
)

type Cluster struct {
Expand All @@ -51,7 +50,7 @@ func NewCluster(client *kubernetes.Clientset, expectedNodes int) *Cluster {
}

func (cl *Cluster) Health() ([]v1.ComponentStatus, error) {
cs, err := cl.KubeClient.CoreV1().ComponentStatuses().List(context.TODO(), meta_v1.ListOptions{})
cs, err := cl.KubeClient.CoreV1().ComponentStatuses().List(context.TODO(), metav1.ListOptions{})
if err != nil {
return nil, err
}
Expand All @@ -76,7 +75,7 @@ type NodeStatus struct {

// GetNodeStatus returns the status for all running nodes or an error.
func (cl *Cluster) GetNodeStatus() (*NodeStatus, error) {
n, err := cl.KubeClient.CoreV1().Nodes().List(context.TODO(), meta_v1.ListOptions{})
n, err := cl.KubeClient.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -140,7 +139,7 @@ func (ns *NodeStatus) PrettyPrint() {

// ping Cluster to know when its endpoint can be used.
func (cl *Cluster) ping() (bool, error) {
_, err := cl.KubeClient.CoreV1().Nodes().List(context.TODO(), meta_v1.ListOptions{})
_, err := cl.KubeClient.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
if err != nil {
return false, nil
}
Expand All @@ -152,7 +151,7 @@ func (cl *Cluster) Verify() error {
fmt.Println("\nNow checking health and readiness of the cluster nodes ...")

// Wait for cluster to become available.
err := retryutil.Retry(clusterPingRetryInterval*time.Second, clusterPingRetries, cl.ping)
err := wait.PollImmediate(clusterPingRetryInterval, clusterPingRetryTimeout, cl.ping)
if err != nil {
return fmt.Errorf("pinging cluster for readiness: %w", err)
}
Expand All @@ -161,7 +160,7 @@ func (cl *Cluster) Verify() error {

var nsErr error

err = retryutil.Retry(nodeReadinessRetryInterval*time.Second, nodeReadinessRetries, func() (bool, error) {
err = wait.PollImmediate(nodeReadinessRetryInterval, nodeReadinessRetryTimeout, func() (bool, error) {
// Store the original error because Retry would stop too early if we forward it
// and anyway overrides the error in case of timeout.
ns, nsErr = cl.GetNodeStatus()
Expand Down
38 changes: 0 additions & 38 deletions pkg/util/path.go

This file was deleted.

64 changes: 0 additions & 64 deletions pkg/util/retryutil/retryutil.go

This file was deleted.

50 changes: 0 additions & 50 deletions pkg/util/tools/tools.go

This file was deleted.

13 changes: 7 additions & 6 deletions test/ingress/aws/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ import (
"testing"
"time"

"github.com/kinvolk/lokomotive/pkg/util/retryutil"
testutil "github.com/kinvolk/lokomotive/test/components/util"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"

testutil "github.com/kinvolk/lokomotive/test/components/util"
)

const (
retryIntervalSeconds = 5
maxRetries = 60
httpTimeout = 4 * time.Second
retryInterval = 5 * time.Second
retryTimeout = 9 * time.Minute
httpTimeout = 4 * time.Second
)

func TestAWSIngress(t *testing.T) {
Expand Down Expand Up @@ -70,7 +71,7 @@ func TestAWSIngress(t *testing.T) {
h := i.Spec.Rules[0].Host
c := getHTTPClient()

err = retryutil.Retry(retryIntervalSeconds*time.Second, maxRetries, func() (bool, error) {
err = wait.PollImmediate(retryInterval, retryTimeout, func() (bool, error) {
resp, err := c.Get(fmt.Sprintf("https://%s/get", h))
if err != nil {
t.Logf("got an HTTP error: %v", err)
Expand Down

0 comments on commit 9033e47

Please sign in to comment.