-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the models command to use the edge client
Using the introduced edge client, refactor the model command to simply use the edge client for listing and adding models. Also refactor the commands design to streamline the flags and commands initialization.
- Loading branch information
Showing
15 changed files
with
840 additions
and
254 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
params: | ||
# The name of the S3 bucket where the model is stored | ||
- name: s3-bucket-name | ||
value: BUCKET_NAME | ||
# The URL of the git repository where the containerfile is stored | ||
- name: git-containerfile-repo | ||
value: GIT_REPO_URL | ||
# The branch of the git repository where the containerfile is stored | ||
- name: git-containerfile-revision | ||
value: GIT_BRANCH | ||
# The relative path to the containerfile in the git repository | ||
- name: containerfileRelativePath | ||
value: RELATIVE_PATH | ||
# The method used to fetch the model (s3 or git) | ||
- name: fetch-model | ||
value: FETCH_METHOD | ||
# The URL of the git repository where the model is stored. This is only used if fetch-model is set to git. | ||
- name: git-model-repo | ||
value: GIT_REPO_URL | ||
# The relative path to the model in the git repository. This is only used if fetch-model is set to git. | ||
- name: modelRelativePath | ||
value: RELATIVE_PATH | ||
# The branch of the git repository where the model is stored. This is only used if fetch-model is set to git. | ||
- name: git-model-revision | ||
value: GIT_BRANCH | ||
# The name of the model serving test endpoint (e.g. invocations) | ||
- name: test-endpoint | ||
value: ENDPOINT_NAME | ||
# The candidate image tag reference. This is the intermediate image that is built during the pipeline. | ||
# e.g. image-registry.openshift-image-registry.svc:5000/$(context.pipelineRun.namespace)/$(params.model-name):$(params.model-version)-candidate | ||
- name: candidate-image-tag-reference | ||
value: CANDIDATE_IMAGE_TAG | ||
# The target image tag references. These are the final images that are pushed to the image registry. A typical value would be: | ||
# - quay.io/rhoai-edge/$(params.model-name):$(params.model-version)-$(context.pipelineRun.uid) | ||
# - quay.io/rhoai-edge/$(params.model-name):$(params.model-version) | ||
# - quay.io/rhoai-edge/$(params.model-name):latest | ||
- name: target-image-tag-references | ||
value: | ||
- TARGET_IMAGE_TAG_1 | ||
- TARGET_IMAGE_TAG_2 | ||
# The action to take upon the completion of the pipeline (e.g. delete) | ||
- name: upon-end | ||
value: ACTION | ||
# The name of the secret that contains the S3 credentials | ||
- name: s3SecretName | ||
value: SECRET_NAME | ||
# The name of the config map that contains the test data |
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,106 @@ | ||
/* | ||
Copyright 2024. Open Data Hub Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package common | ||
|
||
import ( | ||
"os" | ||
|
||
tea "github.com/charmbracelet/bubbletea" | ||
"github.com/opendatahub-io/ai-edge/cli/pkg/commands/flags" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// SubCommand is a type to represent the subcommand | ||
type SubCommand int | ||
|
||
const ( | ||
// SubCommandList is a subcommand to list items | ||
SubCommandList SubCommand = iota | ||
// SubCommandAdd is a subcommand to add items | ||
SubCommandAdd | ||
) | ||
|
||
// NewCmd creates a new cobra command. | ||
// | ||
// The command will create a new tea program, passing the model created by the modelFactory, and run it. | ||
// The modelFactory will be called with the args, flags and subCommand. | ||
// | ||
// Example: | ||
// cmd := NewCmd( | ||
// "images", | ||
// "List images", | ||
// `List images`, | ||
// cobra.ExactArgs(3), | ||
// []flags.Flag{flags.FlagModelRegistryUrl}, | ||
// SubCommandList, | ||
// func(args []string, flags map[string]string, subCommand SubCommand) tea.Model { | ||
// return NewImagesModel(args, flags, subCommand) | ||
// }, | ||
// ) | ||
func NewCmd( | ||
use, short, long string, | ||
args cobra.PositionalArgs, | ||
flags []flags.Flag, | ||
command SubCommand, | ||
modelFactory func(args []string, flags map[string]string, subCommand SubCommand) tea.Model, | ||
) *cobra.Command { | ||
|
||
cmd := cobra.Command{ | ||
Use: use, | ||
Short: short, | ||
Long: long, | ||
Args: args, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
ff := make(map[string]string) | ||
for _, f := range flags { | ||
v := "" | ||
err := error(nil) | ||
if f.IsInherited() { | ||
v, err = cmd.InheritedFlags().GetString(f.String()) | ||
if err != nil { | ||
cmd.PrintErrf("Error reading inherited flag %s: %v\n", f, err) | ||
os.Exit(1) | ||
} | ||
} else { | ||
v, err = cmd.Flags().GetString(f.String()) | ||
if err != nil { | ||
cmd.PrintErrf("Error reading flag %s: %v\n", f, err) | ||
os.Exit(1) | ||
} | ||
} | ||
ff[f.String()] = v | ||
} | ||
_, err := tea.NewProgram(modelFactory(args, ff, command)).Run() | ||
if err != nil { | ||
cmd.PrintErrf("Error: %v\n", err) | ||
os.Exit(1) | ||
} | ||
}, | ||
} | ||
|
||
for _, f := range flags { | ||
if !f.IsParentFlag() { | ||
if f.IsInherited() { | ||
cmd.PersistentFlags().StringP(f.String(), f.Shorthand(), f.Value(), f.Usage()) | ||
} else { | ||
cmd.Flags().StringP(f.String(), f.Shorthand(), f.Value(), f.Usage()) | ||
} | ||
} | ||
} | ||
|
||
return &cmd | ||
} |
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,25 @@ | ||
/* | ||
Copyright 2024. Open Data Hub Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package common | ||
|
||
// ErrMsg is a wrapper for an error that implements the error interface. | ||
// | ||
// This is useful for returning an error from a model in the bubbletea program. | ||
type ErrMsg struct{ Err error } | ||
|
||
// Error returns the error message. | ||
func (e ErrMsg) Error() string { return e.Err.Error() } |
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,35 @@ | ||
/* | ||
Copyright 2024. Open Data Hub Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package common | ||
|
||
import "github.com/charmbracelet/lipgloss" | ||
|
||
// TableBaseStyle is the base style for the table | ||
var TableBaseStyle = lipgloss.NewStyle(). | ||
BorderStyle(lipgloss.NormalBorder()). | ||
BorderForeground(lipgloss.Color("#04B575")) | ||
|
||
// MessageStyle is the style for regular messages | ||
var MessageStyle = lipgloss.NewStyle(). | ||
Bold(true) | ||
|
||
// ErrorStyle is the style for error messages | ||
var ErrorStyle = lipgloss.NewStyle(). | ||
Foreground(lipgloss.Color("#FF0000")). | ||
Bold(true). | ||
Height(4). | ||
Width(120) |
Oops, something went wrong.