1
0
mirror of synced 2026-02-06 19:05:55 +00:00

Adds a watch flag to the get command

The new flag fetch and display the request ressource and then continue
watching the ressource until timeout or cancellation.

A single ressource/ressource type is supported.

Signed-off-by: Soule BA <soule@weave.works>
This commit is contained in:
Soule BA
2021-08-02 15:49:29 +02:00
parent d1970185b9
commit c18d0b9217
22 changed files with 534 additions and 67 deletions

View File

@@ -134,7 +134,7 @@ func KubeConfig(kubeConfigPath string, kubeContext string) (*rest.Config, error)
// KubeManger creates a Kubernetes client.Client. This interface exists to
// facilitate unit testing and provide a fake client.
type KubeManager interface {
NewClient(string, string) (client.Client, error)
NewClient(string, string) (client.WithWatch, error)
}
type defaultKubeManager struct{}
@@ -144,14 +144,14 @@ func DefaultKubeManager() KubeManager {
return manager
}
func (m defaultKubeManager) NewClient(kubeConfigPath string, kubeContext string) (client.Client, error) {
func (m defaultKubeManager) NewClient(kubeConfigPath string, kubeContext string) (client.WithWatch, error) {
cfg, err := KubeConfig(kubeConfigPath, kubeContext)
if err != nil {
return nil, fmt.Errorf("kubernetes client initialization failed: %w", err)
}
scheme := NewScheme()
kubeClient, err := client.New(cfg, client.Options{
kubeClient, err := client.NewWithWatch(cfg, client.Options{
Scheme: scheme,
})
if err != nil {
@@ -179,7 +179,7 @@ func NewScheme() *apiruntime.Scheme {
return scheme
}
func KubeClient(kubeConfigPath string, kubeContext string) (client.Client, error) {
func KubeClient(kubeConfigPath string, kubeContext string) (client.WithWatch, error) {
m := DefaultKubeManager()
kubeClient, err := m.NewClient(kubeConfigPath, kubeContext)
return kubeClient, err