-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from Charliekenney23/feat/waitForLKEClusterReady
implement WaitForLKEClusterReady
- Loading branch information
Showing
14 changed files
with
937 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package kubernetes | ||
|
||
import ( | ||
"fmt" | ||
|
||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/tools/clientcmd" | ||
"k8s.io/client-go/transport" | ||
) | ||
|
||
// Clientset is an alias to k8s.io/client-go/kubernetes.Interface | ||
type Clientset kubernetes.Interface | ||
|
||
// NewClientsetFromBytes builds a Clientset from a given Kubeconfig. | ||
// | ||
// Takes an optional transport.WrapperFunc to add request/response middleware to | ||
// api-server requests. | ||
func BuildClientsetFromConfig( | ||
kubeconfigBytes []byte, | ||
transportWrapper transport.WrapperFunc, | ||
) (Clientset, error) { | ||
config, err := clientcmd.NewClientConfigFromBytes(kubeconfigBytes) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse LKE cluster kubeconfig: %s", err) | ||
} | ||
|
||
restClientConfig, err := config.ClientConfig() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get REST client config: %s", err) | ||
} | ||
|
||
if transportWrapper != nil { | ||
restClientConfig.Wrap(transportWrapper) | ||
} | ||
|
||
clientset, err := kubernetes.NewForConfig(restClientConfig) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to build k8s client from LKE cluster kubeconfig: %s", err) | ||
} | ||
return clientset, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Package condition provides strategies for waiting for infrastructure | ||
// to reach a desired state through conditional predicates. | ||
package condition |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package condition | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/linode/linodego/internal/kubernetes" | ||
corev1 "k8s.io/api/core/v1" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// ClusterConditionFunc represents a function that tests a condition against an LKE cluster, | ||
// returns true if the condition has been reached, false if it has not yet been reached. | ||
type ClusterConditionFunc func(context.Context, kubernetes.Clientset) (bool, error) | ||
|
||
// ClusterHasReadyNode is a ClusterConditionFunc which polls for at least one node to have the | ||
// condition NodeReady=True. | ||
func ClusterHasReadyNode(ctx context.Context, clientset kubernetes.Clientset) (bool, error) { | ||
nodes, err := clientset.CoreV1().Nodes().List(v1.ListOptions{}) | ||
if err != nil { | ||
return false, fmt.Errorf("failed to get nodes for cluster: %s", err) | ||
} | ||
|
||
for _, node := range nodes.Items { | ||
for _, condition := range node.Status.Conditions { | ||
if condition.Type == corev1.NodeReady && condition.Status == corev1.ConditionTrue { | ||
return true, nil | ||
} | ||
} | ||
} | ||
|
||
return false, errors.New("no nodes in cluster are ready") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.