From f1fc2659bec626a7af52196ccff16da1c1486231 Mon Sep 17 00:00:00 2001 From: Nick Stogner Date: Wed, 2 Aug 2023 19:31:13 -0400 Subject: [PATCH] Checkpoint --- Makefile | 14 +++++++++++--- install/scripts/install-kubectl-plugins.sh | 14 ++++++++++++++ install/scripts/install_kubectl_plugin.sh | 19 ------------------- kubectl/internal/client/sync.go | 12 ++++++------ kubectl/internal/commands/applybuild.go | 16 ++++------------ kubectl/internal/commands/notebook.go | 11 +---------- kubectl/internal/commands/utils.go | 4 ++++ 7 files changed, 40 insertions(+), 50 deletions(-) create mode 100755 install/scripts/install-kubectl-plugins.sh delete mode 100755 install/scripts/install_kubectl_plugin.sh diff --git a/Makefile b/Makefile index a7f693f3..b6f62977 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # Image URL to use all building/pushing image targets -VERSION ?= v0.7.0-alpha +VERSION ?= v0.8.0 IMG ?= docker.io/substratusai/controller-manager:${VERSION} IMG_GCPMANAGER ?= docker.io/substratusai/gcp-manager:${VERSION} @@ -145,7 +145,7 @@ dev-run: export CLOUD=gcp dev-run: export GPU_TYPE=nvidia-l4 dev-run: export PROJECT_ID=$(shell gcloud config get project) dev-run: export CLUSTER_NAME=substratus -dev-run: export CLUSTER_LOCATION=us-central1 +dev-run: export CLUSTER_LOCATION=us-east1 # Cloud manager configuration # dev-run: export GOOGLE_APPLICATION_CREDENTIALS=./secrets/gcp-manager-key.json # Run the controller manager and the cloud manager. @@ -216,11 +216,19 @@ install-crds: manifests kustomize ## Install CRDs into the K8s cluster specified uninstall-crds: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. $(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f - -install/kubernetes/system.yaml: manifests kustomize +.PHONY: installation-scripts +installation-scripts: + perl -pi -e "s/version=.*/version=$(VERSION)/g" install/scripts/install-kubectl-plugins.sh + +.PHONY: installation-manifests +installation-manifests: manifests kustomize cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} cd config/gcpmanager && $(KUSTOMIZE) edit set image gcp-manager=${IMG_GCPMANAGER} $(KUSTOMIZE) build config/default > install/kubernetes/system.yaml +.PHONY: prepare-release +prepare-release: installation-scripts installation-manifests docs + ##@ Build Dependencies ## Location to install dependencies to diff --git a/install/scripts/install-kubectl-plugins.sh b/install/scripts/install-kubectl-plugins.sh new file mode 100755 index 00000000..9e5b8411 --- /dev/null +++ b/install/scripts/install-kubectl-plugins.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +set -xe + +version=v0.8.0 +os=$(uname -s) +arch=$(uname -m | sed 's/aarch64/arm64/g') + +release_url="https://github.com/substratusai/substratus/releases/download/$version/kubectl-plugins-$os-$arch.tar.gz" + +wget -qO- $release_url | tar zxv --directory /tmp +chmod +x /tmp/kubectl-applybuild +chmod +x /tmp/kubectl-notebook +mv /tmp/kubectl-applybuild /usr/local/bin/ || sudo mv /tmp/kubectl-applybuild /usr/local/bin/ +mv /tmp/kubectl-notebook /usr/local/bin/ || sudo mv /tmp/kubectl-notebook /usr/local/bin/ diff --git a/install/scripts/install_kubectl_plugin.sh b/install/scripts/install_kubectl_plugin.sh deleted file mode 100755 index ab483554..00000000 --- a/install/scripts/install_kubectl_plugin.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash -set -xe - -REPO='https://github.com/substratusai/substratus' -LATEST_RELEASE=$(curl ${REPO}/releases -s | - grep 'Link--primary' | - head -n1 | - perl -n -e '/v([0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?)/ && print $&') -OS=$(uname -s) -ARCH=$(uname -m | sed 's/aarch64/arm64/g') -LATEST_OPEN_NOTEBOOK_ARTIFACT_URL=$(echo $LATEST_RELEASE | awk -v repo=$REPO -v os=$OS -v arch=$ARCH -v release=$LATEST_RELEASE '{print repo "/releases/download/" release "/kubectl-open-notebook_" os "_" arch ".tar.gz"}') -LATEST_BUILD_REMOTE_ARTIFACT_URL=$(echo $LATEST_RELEASE | awk -v repo=$REPO -v os=$OS -v arch=$ARCH -v release=$LATEST_RELEASE '{print repo "/releases/download/" release "/kubectl-build-remote_" os "_" arch ".tar.gz"}') - -wget -qO- ${LATEST_OPEN_NOTEBOOK_ARTIFACT_URL} | tar zxv -wget -qO- ${LATEST_BUILD_REMOTE_ARTIFACT_URL} | tar zxv -chmod +x kubectl-open-notebook -chmod +x kubectl-build-remote -mv kubectl-open-notebook /usr/local/bin/ || sudo mv kubectl-open-notebook /usr/local/bin/ -mv kubectl-build-remote /usr/local/bin/ || sudo mv kubectl-build-remote /usr/local/bin/ diff --git a/kubectl/internal/client/sync.go b/kubectl/internal/client/sync.go index 47b400e3..acc79f77 100644 --- a/kubectl/internal/client/sync.go +++ b/kubectl/internal/client/sync.go @@ -32,24 +32,24 @@ func (c *Client) SyncFilesFromNotebook(ctx context.Context, nb *apiv1.Notebook) if err != nil { return fmt.Errorf("determining user cache directory: %w", err) } - binPath := filepath.Join(cacheDir, "substratus", "container-tools") - if err := os.MkdirAll(filepath.Dir(binPath), 0755); err != nil { + toolsPath := filepath.Join(cacheDir, "substratus", "container-tools") + if err := os.MkdirAll(toolsPath, 0755); err != nil { return fmt.Errorf("creating cache directory: %w", err) } const ( // TODO: Detect OS and Arch: - targetOS = "Linux" + targetOS = "linux" targetArch = "x86_64" ) - if err := getContainerTools(binPath, targetOS, targetArch); err != nil { - return fmt.Errorf("getting nbwatch: %w", err) + if err := getContainerTools(toolsPath, targetOS, targetArch); err != nil { + return fmt.Errorf("getting container-tools: %w", err) } // TODO: Download nbwatch if it doesn't exist. - if err := cp.ToPod(ctx, binPath, "/tmp/nbwatch", podRef, containerName); err != nil { + if err := cp.ToPod(ctx, toolsPath, "/tmp/nbwatch", podRef, containerName); err != nil { return fmt.Errorf("cp nbwatch to pod: %w", err) } diff --git a/kubectl/internal/commands/applybuild.go b/kubectl/internal/commands/applybuild.go index 7d02436c..9d6e4153 100644 --- a/kubectl/internal/commands/applybuild.go +++ b/kubectl/internal/commands/applybuild.go @@ -19,22 +19,16 @@ func ApplyBuild() *cobra.Command { build string kubeconfig string forceConflicts bool - version bool } var cmd = &cobra.Command{ - Use: "applybuild [flags] BUILD_CONTEXT", - Args: cobra.ExactArgs(1), - Short: "Apply a Substratus object, upload and build container in-cluster from a local directory", + Use: "applybuild [flags] BUILD_CONTEXT", + Args: cobra.ExactArgs(1), + Short: "Apply a Substratus object, upload and build container in-cluster from a local directory", + Version: Version, RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() - client.Version = Version - if cfg.version { - fmt.Printf("kubectl-applybuild %v\n", Version) - return nil - } - if cfg.filename == "" { return fmt.Errorf("-f (--filename) is required") } @@ -103,8 +97,6 @@ func ApplyBuild() *cobra.Command { cmd.Flags().StringVarP(&cfg.filename, "filename", "f", "", "Filename identifying the resource to apply and build.") cmd.Flags().BoolVar(&cfg.forceConflicts, "force-conflicts", false, "If true, server-side apply will force the changes against conflicts.") - cmd.Flags().BoolVar(&cfg.version, "version", false, "Print version of tool") - // Add standard kubectl logging flags (for example: -v=2). goflags := flag.NewFlagSet("", flag.PanicOnError) klog.InitFlags(goflags) diff --git a/kubectl/internal/commands/notebook.go b/kubectl/internal/commands/notebook.go index 449699e8..67ba53b3 100644 --- a/kubectl/internal/commands/notebook.go +++ b/kubectl/internal/commands/notebook.go @@ -37,7 +37,6 @@ func Notebook() *cobra.Command { forceConflicts bool noSuspend bool timeout time.Duration - version bool } var cmd = &cobra.Command{ @@ -48,12 +47,6 @@ func Notebook() *cobra.Command { ctx, cancel := context.WithCancel(cmd.Context()) defer cancel() - client.Version = Version - if cfg.version { - fmt.Fprintf(NotebookStdout, "kubectl-notebook %v\n", Version) - return nil - } - // The -v flag is managed by klog, so we need to check it manually. var verbose bool if cmd.Flag("v").Changed { @@ -215,7 +208,7 @@ func Notebook() *cobra.Command { go func() { defer func() { wg.Done() - klog.V(2).Info("Syncing files form notebook: Done.") + klog.V(2).Info("Syncing files from notebook: Done.") }() if err := c.SyncFilesFromNotebook(ctx, nb); err != nil { @@ -318,8 +311,6 @@ func Notebook() *cobra.Command { cmd.Flags().BoolVar(&cfg.noOpenBrowser, "no-open-browser", false, "Do not open the Notebook in a browser") cmd.Flags().DurationVarP(&cfg.timeout, "timeout", "t", 20*time.Minute, "Timeout for Notebook to become ready") - cmd.Flags().BoolVar(&cfg.version, "version", false, "Print version of tool") - // Add standard kubectl logging flags (for example: -v=2). goflags := flag.NewFlagSet("", flag.PanicOnError) klog.InitFlags(goflags) diff --git a/kubectl/internal/commands/utils.go b/kubectl/internal/commands/utils.go index 81550c66..46cd9965 100644 --- a/kubectl/internal/commands/utils.go +++ b/kubectl/internal/commands/utils.go @@ -8,6 +8,10 @@ import ( "github.com/substratusai/substratus/kubectl/internal/client" ) +func init() { + client.Version = Version +} + var Version = "development" // NewClient is a dirty hack to allow the client to be mocked out in tests.