This repository has been archived by the owner on May 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# TL;DR This will let flytectl demo use the new bundled sandbox image instead. See the issue for additional information. `flytectl demo start` * Brings up the new container * kubeconfig will now be published to `~/.flyte/state/kubeconfig` (but the context will still be copied to the user's main kubeconfig with "flyte-sandbox" as the context name). `flytectl demo reload` Kills the Flyte pod, allowing the new one to come up. Signed-off-by: Yee Hing Tong <[email protected]>
- Loading branch information
1 parent
209fe93
commit b523c54
Showing
22 changed files
with
726 additions
and
108 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,58 @@ | ||
package demo | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
cmdCore "github.com/flyteorg/flytectl/cmd/core" | ||
"github.com/flyteorg/flytectl/pkg/docker" | ||
"github.com/flyteorg/flytectl/pkg/k8s" | ||
"github.com/flyteorg/flytestdlib/logger" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
const ( | ||
labelSelector = "app=flyte" | ||
) | ||
const ( | ||
reloadShort = "Power cycle the Flyte executable pod, effectively picking up an updated config." | ||
reloadLong = ` | ||
If you've changed the ~/.flyte/state/flyte.yaml file, run this command to restart the Flyte binary pod, effectively | ||
picking up the new settings: | ||
Usage | ||
:: | ||
flytectl demo reload | ||
` | ||
) | ||
|
||
// reloadDemoCluster will kill the flyte binary pod so the new one can pick up a new config file | ||
func reloadDemoCluster(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error { | ||
k8sClient, err := k8s.GetK8sClient(docker.Kubeconfig, K8sEndpoint) | ||
if err != nil { | ||
fmt.Println("Could not get K8s client") | ||
return err | ||
} | ||
pi := k8sClient.CoreV1().Pods(flyteNs) | ||
podList, err := pi.List(ctx, v1.ListOptions{LabelSelector: labelSelector}) | ||
if err != nil { | ||
fmt.Println("could not list pods") | ||
return err | ||
} | ||
if len(podList.Items) != 1 { | ||
return fmt.Errorf("should only have one pod running, %d found, %v", len(podList.Items), podList.Items) | ||
} | ||
logger.Debugf(ctx, "Found %d pods\n", len(podList.Items)) | ||
var grace = int64(0) | ||
err = pi.Delete(ctx, podList.Items[0].Name, v1.DeleteOptions{ | ||
GracePeriodSeconds: &grace, | ||
}) | ||
if err != nil { | ||
fmt.Printf("Could not delete Flyte pod, old configuration may still be in effect. Err: %s\n", err) | ||
return err | ||
} | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package demo | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
cmdCore "github.com/flyteorg/flytectl/cmd/core" | ||
"github.com/flyteorg/flytectl/pkg/k8s" | ||
"github.com/stretchr/testify/assert" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
testclient "k8s.io/client-go/kubernetes/fake" | ||
) | ||
|
||
var fakePod = corev1.Pod{ | ||
Status: corev1.PodStatus{ | ||
Phase: corev1.PodRunning, | ||
Conditions: []corev1.PodCondition{}, | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "dummyflytepod", | ||
Labels: map[string]string{"app": "flyte"}, | ||
}, | ||
} | ||
|
||
func TestDemoReload(t *testing.T) { | ||
ctx := context.Background() | ||
commandCtx := cmdCore.CommandContext{} | ||
|
||
t.Run("No errors", func(t *testing.T) { | ||
client := testclient.NewSimpleClientset() | ||
_, err := client.CoreV1().Pods("flyte").Create(ctx, &fakePod, v1.CreateOptions{}) | ||
assert.NoError(t, err) | ||
k8s.Client = client | ||
err = reloadDemoCluster(ctx, []string{}, commandCtx) | ||
assert.NoError(t, err) | ||
}) | ||
|
||
t.Run("Multiple pods will error", func(t *testing.T) { | ||
client := testclient.NewSimpleClientset() | ||
_, err := client.CoreV1().Pods("flyte").Create(ctx, &fakePod, v1.CreateOptions{}) | ||
assert.NoError(t, err) | ||
fakePod.SetName("othername") | ||
_, err = client.CoreV1().Pods("flyte").Create(ctx, &fakePod, v1.CreateOptions{}) | ||
assert.NoError(t, err) | ||
k8s.Client = client | ||
err = reloadDemoCluster(ctx, []string{}, commandCtx) | ||
assert.Errorf(t, err, "should only have one pod") | ||
}) | ||
} |
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
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.