Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
nstogner committed Aug 2, 2023
1 parent 073a507 commit f1fc265
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 50 deletions.
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions install/scripts/install-kubectl-plugins.sh
Original file line number Diff line number Diff line change
@@ -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/
19 changes: 0 additions & 19 deletions install/scripts/install_kubectl_plugin.sh

This file was deleted.

12 changes: 6 additions & 6 deletions kubectl/internal/client/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
16 changes: 4 additions & 12 deletions kubectl/internal/commands/applybuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 1 addition & 10 deletions kubectl/internal/commands/notebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func Notebook() *cobra.Command {
forceConflicts bool
noSuspend bool
timeout time.Duration
version bool
}

var cmd = &cobra.Command{
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions kubectl/internal/commands/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit f1fc265

Please sign in to comment.