Skip to content

Commit

Permalink
Update garm-provider-common package
Browse files Browse the repository at this point in the history
  • Loading branch information
fabi200123 committed Aug 21, 2024
1 parent 03f280d commit c9724a7
Show file tree
Hide file tree
Showing 18 changed files with 1,248 additions and 296 deletions.
18 changes: 9 additions & 9 deletions runner/providers/v0.1.0/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/pkg/errors"

garmErrors "github.com/cloudbase/garm-provider-common/errors"
execution "github.com/cloudbase/garm-provider-common/execution/v0.1.0"
commonExecution "github.com/cloudbase/garm-provider-common/execution/common"
commonParams "github.com/cloudbase/garm-provider-common/params"
garmExec "github.com/cloudbase/garm-provider-common/util/exec"
"github.com/cloudbase/garm/config"
Expand Down Expand Up @@ -76,7 +76,7 @@ func (e *external) validateResult(inst commonParams.ProviderInstance) error {
// CreateInstance creates a new compute instance in the provider.
func (e *external) CreateInstance(ctx context.Context, bootstrapParams commonParams.BootstrapInstance, _ common.CreateInstanceParams) (commonParams.ProviderInstance, error) {
asEnv := []string{
fmt.Sprintf("GARM_COMMAND=%s", execution.CreateInstanceCommand),
fmt.Sprintf("GARM_COMMAND=%s", commonExecution.CreateInstanceCommand),
fmt.Sprintf("GARM_CONTROLLER_ID=%s", e.controllerID),
fmt.Sprintf("GARM_POOL_ID=%s", bootstrapParams.PoolID),
fmt.Sprintf("GARM_PROVIDER_CONFIG_FILE=%s", e.cfg.External.ConfigFile),
Expand Down Expand Up @@ -129,7 +129,7 @@ func (e *external) CreateInstance(ctx context.Context, bootstrapParams commonPar
// Delete instance will delete the instance in a provider.
func (e *external) DeleteInstance(ctx context.Context, instance string, _ common.DeleteInstanceParams) error {
asEnv := []string{
fmt.Sprintf("GARM_COMMAND=%s", execution.DeleteInstanceCommand),
fmt.Sprintf("GARM_COMMAND=%s", commonExecution.DeleteInstanceCommand),
fmt.Sprintf("GARM_CONTROLLER_ID=%s", e.controllerID),
fmt.Sprintf("GARM_INSTANCE_ID=%s", instance),
fmt.Sprintf("GARM_PROVIDER_CONFIG_FILE=%s", e.cfg.External.ConfigFile),
Expand All @@ -143,7 +143,7 @@ func (e *external) DeleteInstance(ctx context.Context, instance string, _ common
_, err := garmExec.Exec(ctx, e.execPath, nil, asEnv)
if err != nil {
var exitErr *exec.ExitError
if !errors.As(err, &exitErr) || exitErr.ExitCode() != execution.ExitCodeNotFound {
if !errors.As(err, &exitErr) || exitErr.ExitCode() != commonExecution.ExitCodeNotFound {
metrics.InstanceOperationFailedCount.WithLabelValues(
"DeleteInstance", // label: operation
e.cfg.Name, // label: provider
Expand All @@ -157,7 +157,7 @@ func (e *external) DeleteInstance(ctx context.Context, instance string, _ common
// GetInstance will return details about one instance.
func (e *external) GetInstance(ctx context.Context, instance string, _ common.GetInstanceParams) (commonParams.ProviderInstance, error) {
asEnv := []string{
fmt.Sprintf("GARM_COMMAND=%s", execution.GetInstanceCommand),
fmt.Sprintf("GARM_COMMAND=%s", commonExecution.GetInstanceCommand),
fmt.Sprintf("GARM_CONTROLLER_ID=%s", e.controllerID),
fmt.Sprintf("GARM_INSTANCE_ID=%s", instance),
fmt.Sprintf("GARM_PROVIDER_CONFIG_FILE=%s", e.cfg.External.ConfigFile),
Expand Down Expand Up @@ -203,7 +203,7 @@ func (e *external) GetInstance(ctx context.Context, instance string, _ common.Ge
// ListInstances will list all instances for a provider.
func (e *external) ListInstances(ctx context.Context, poolID string, _ common.ListInstancesParams) ([]commonParams.ProviderInstance, error) {
asEnv := []string{
fmt.Sprintf("GARM_COMMAND=%s", execution.ListInstancesCommand),
fmt.Sprintf("GARM_COMMAND=%s", commonExecution.ListInstancesCommand),
fmt.Sprintf("GARM_CONTROLLER_ID=%s", e.controllerID),
fmt.Sprintf("GARM_POOL_ID=%s", poolID),
fmt.Sprintf("GARM_PROVIDER_CONFIG_FILE=%s", e.cfg.External.ConfigFile),
Expand Down Expand Up @@ -250,7 +250,7 @@ func (e *external) ListInstances(ctx context.Context, poolID string, _ common.Li
// RemoveAllInstances will remove all instances created by this provider.
func (e *external) RemoveAllInstances(ctx context.Context, _ common.RemoveAllInstancesParams) error {
asEnv := []string{
fmt.Sprintf("GARM_COMMAND=%s", execution.RemoveAllInstancesCommand),
fmt.Sprintf("GARM_COMMAND=%s", commonExecution.RemoveAllInstancesCommand),
fmt.Sprintf("GARM_CONTROLLER_ID=%s", e.controllerID),
fmt.Sprintf("GARM_PROVIDER_CONFIG_FILE=%s", e.cfg.External.ConfigFile),
}
Expand All @@ -275,7 +275,7 @@ func (e *external) RemoveAllInstances(ctx context.Context, _ common.RemoveAllIns
// Stop shuts down the instance.
func (e *external) Stop(ctx context.Context, instance string, _ common.StopParams) error {
asEnv := []string{
fmt.Sprintf("GARM_COMMAND=%s", execution.StopInstanceCommand),
fmt.Sprintf("GARM_COMMAND=%s", commonExecution.StopInstanceCommand),
fmt.Sprintf("GARM_CONTROLLER_ID=%s", e.controllerID),
fmt.Sprintf("GARM_INSTANCE_ID=%s", instance),
fmt.Sprintf("GARM_PROVIDER_CONFIG_FILE=%s", e.cfg.External.ConfigFile),
Expand All @@ -300,7 +300,7 @@ func (e *external) Stop(ctx context.Context, instance string, _ common.StopParam
// Start boots up an instance.
func (e *external) Start(ctx context.Context, instance string, _ common.StartParams) error {
asEnv := []string{
fmt.Sprintf("GARM_COMMAND=%s", execution.StartInstanceCommand),
fmt.Sprintf("GARM_COMMAND=%s", commonExecution.StartInstanceCommand),
fmt.Sprintf("GARM_CONTROLLER_ID=%s", e.controllerID),
fmt.Sprintf("GARM_INSTANCE_ID=%s", instance),
fmt.Sprintf("GARM_PROVIDER_CONFIG_FILE=%s", e.cfg.External.ConfigFile),
Expand Down
18 changes: 9 additions & 9 deletions runner/providers/v0.1.1/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/pkg/errors"

garmErrors "github.com/cloudbase/garm-provider-common/errors"
execution "github.com/cloudbase/garm-provider-common/execution/v0.1.1"
commonExecution "github.com/cloudbase/garm-provider-common/execution/common"
commonParams "github.com/cloudbase/garm-provider-common/params"
garmExec "github.com/cloudbase/garm-provider-common/util/exec"
"github.com/cloudbase/garm/config"
Expand Down Expand Up @@ -75,7 +75,7 @@ func (e *external) validateResult(inst commonParams.ProviderInstance) error {
// CreateInstance creates a new compute instance in the provider.
func (e *external) CreateInstance(ctx context.Context, bootstrapParams commonParams.BootstrapInstance, _ common.CreateInstanceParams) (commonParams.ProviderInstance, error) {
asEnv := []string{
fmt.Sprintf("GARM_COMMAND=%s", execution.CreateInstanceCommand),
fmt.Sprintf("GARM_COMMAND=%s", commonExecution.CreateInstanceCommand),
fmt.Sprintf("GARM_CONTROLLER_ID=%s", e.controllerID),
fmt.Sprintf("GARM_POOL_ID=%s", bootstrapParams.PoolID),
fmt.Sprintf("GARM_PROVIDER_CONFIG_FILE=%s", e.cfg.External.ConfigFile),
Expand Down Expand Up @@ -135,7 +135,7 @@ func (e *external) DeleteInstance(ctx context.Context, instance string, deleteIn
// Encode the extraspecs as base64 to avoid issues with special characters.
base64EncodedExtraSpecs := base64.StdEncoding.EncodeToString(extraspecsValue)
asEnv := []string{
fmt.Sprintf("GARM_COMMAND=%s", execution.DeleteInstanceCommand),
fmt.Sprintf("GARM_COMMAND=%s", commonExecution.DeleteInstanceCommand),
fmt.Sprintf("GARM_CONTROLLER_ID=%s", e.controllerID),
fmt.Sprintf("GARM_INSTANCE_ID=%s", instance),
fmt.Sprintf("GARM_PROVIDER_CONFIG_FILE=%s", e.cfg.External.ConfigFile),
Expand All @@ -151,7 +151,7 @@ func (e *external) DeleteInstance(ctx context.Context, instance string, deleteIn
_, err = garmExec.Exec(ctx, e.execPath, nil, asEnv)
if err != nil {
var exitErr *exec.ExitError
if !errors.As(err, &exitErr) || exitErr.ExitCode() != execution.ExitCodeNotFound {
if !errors.As(err, &exitErr) || exitErr.ExitCode() != commonExecution.ExitCodeNotFound {
metrics.InstanceOperationFailedCount.WithLabelValues(
"DeleteInstance", // label: operation
e.cfg.Name, // label: provider
Expand All @@ -172,7 +172,7 @@ func (e *external) GetInstance(ctx context.Context, instance string, getInstance
// Encode the extraspecs as base64 to avoid issues with special characters.
base64EncodedExtraSpecs := base64.StdEncoding.EncodeToString(extraspecsValue)
asEnv := []string{
fmt.Sprintf("GARM_COMMAND=%s", execution.GetInstanceCommand),
fmt.Sprintf("GARM_COMMAND=%s", commonExecution.GetInstanceCommand),
fmt.Sprintf("GARM_CONTROLLER_ID=%s", e.controllerID),
fmt.Sprintf("GARM_INSTANCE_ID=%s", instance),
fmt.Sprintf("GARM_PROVIDER_CONFIG_FILE=%s", e.cfg.External.ConfigFile),
Expand Down Expand Up @@ -227,7 +227,7 @@ func (e *external) ListInstances(ctx context.Context, poolID string, listInstanc
// Encode the extraspecs as base64 to avoid issues with special characters.
base64EncodedExtraSpecs := base64.StdEncoding.EncodeToString(extraspecsValue)
asEnv := []string{
fmt.Sprintf("GARM_COMMAND=%s", execution.ListInstancesCommand),
fmt.Sprintf("GARM_COMMAND=%s", commonExecution.ListInstancesCommand),
fmt.Sprintf("GARM_CONTROLLER_ID=%s", e.controllerID),
fmt.Sprintf("GARM_POOL_ID=%s", poolID),
fmt.Sprintf("GARM_PROVIDER_CONFIG_FILE=%s", e.cfg.External.ConfigFile),
Expand Down Expand Up @@ -282,7 +282,7 @@ func (e *external) RemoveAllInstances(ctx context.Context, removeAllInstances co
// Encode the extraspecs as base64 to avoid issues with special characters.
base64EncodedExtraSpecs := base64.StdEncoding.EncodeToString(extraspecsValue)
asEnv := []string{
fmt.Sprintf("GARM_COMMAND=%s", execution.RemoveAllInstancesCommand),
fmt.Sprintf("GARM_COMMAND=%s", commonExecution.RemoveAllInstancesCommand),
fmt.Sprintf("GARM_CONTROLLER_ID=%s", e.controllerID),
fmt.Sprintf("GARM_PROVIDER_CONFIG_FILE=%s", e.cfg.External.ConfigFile),
fmt.Sprintf("GARM_POOL_ID=%s", removeAllInstances.RemoveAllInstancesV011.PoolInfo.ID),
Expand Down Expand Up @@ -316,7 +316,7 @@ func (e *external) Stop(ctx context.Context, instance string, stopParams common.
// Encode the extraspecs as base64 to avoid issues with special characters.
base64EncodedExtraSpecs := base64.StdEncoding.EncodeToString(extraspecsValue)
asEnv := []string{
fmt.Sprintf("GARM_COMMAND=%s", execution.StopInstanceCommand),
fmt.Sprintf("GARM_COMMAND=%s", commonExecution.StopInstanceCommand),
fmt.Sprintf("GARM_CONTROLLER_ID=%s", e.controllerID),
fmt.Sprintf("GARM_INSTANCE_ID=%s", instance),
fmt.Sprintf("GARM_PROVIDER_CONFIG_FILE=%s", e.cfg.External.ConfigFile),
Expand Down Expand Up @@ -350,7 +350,7 @@ func (e *external) Start(ctx context.Context, instance string, startParams commo
// Encode the extraspecs as base64 to avoid issues with special characters.
base64EncodedExtraSpecs := base64.StdEncoding.EncodeToString(extraspecsValue)
asEnv := []string{
fmt.Sprintf("GARM_COMMAND=%s", execution.StartInstanceCommand),
fmt.Sprintf("GARM_COMMAND=%s", commonExecution.StartInstanceCommand),
fmt.Sprintf("GARM_CONTROLLER_ID=%s", e.controllerID),
fmt.Sprintf("GARM_INSTANCE_ID=%s", instance),
fmt.Sprintf("GARM_PROVIDER_CONFIG_FILE=%s", e.cfg.External.ConfigFile),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c9724a7

Please sign in to comment.