-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Matchable resource support in flytectl for task resource attributes (#63
) * Adding commands for task resource attributes support Signed-off-by: Prafulla Mahindrakar <[email protected]>
- Loading branch information
1 parent
a0632f0
commit 661de8d
Showing
82 changed files
with
2,961 additions
and
259 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 |
---|---|---|
|
@@ -6,3 +6,4 @@ bin | |
_test | ||
./config.yaml | ||
docs/build/* | ||
cmd/get/temp-output-file |
10 changes: 10 additions & 0 deletions
10
flytectl/cmd/config/subcommand/task_resource_attribute_delete_config.go
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,10 @@ | ||
package subcommand | ||
|
||
//go:generate pflags TaskResourceAttrDeleteConfig --default-var DefaultTaskResourceDelConfig | ||
|
||
// TaskResourceAttrDeleteConfig Matchable resource attributes configuration passed from command line | ||
type TaskResourceAttrDeleteConfig struct { | ||
AttrFile string `json:"attrFile" pflag:",attribute file name to be used for delete attribute for the resource type."` | ||
} | ||
|
||
var DefaultTaskResourceDelConfig = &TaskResourceAttrDeleteConfig{} |
9 changes: 9 additions & 0 deletions
9
flytectl/cmd/config/subcommand/task_resource_attribute_fetch_config.go
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,9 @@ | ||
package subcommand | ||
|
||
//go:generate pflags TaskResourceAttrFetchConfig --default-var DefaultTaskResourceFetchConfig | ||
|
||
type TaskResourceAttrFetchConfig struct { | ||
AttrFile string `json:"attrFile" pflag:",attribute file name to be used for generating attribute for the resource type."` | ||
} | ||
|
||
var DefaultTaskResourceFetchConfig = &TaskResourceAttrFetchConfig{} |
86 changes: 86 additions & 0 deletions
86
flytectl/cmd/config/subcommand/task_resource_attribute_file_config.go
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,86 @@ | ||
package subcommand | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
cmdUtil "github.com/flyteorg/flytectl/pkg/commandutils" | ||
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" | ||
"github.com/flyteorg/flytestdlib/logger" | ||
|
||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
// TaskResourceAttrFileConfig shadow config for TaskResourceAttribute. | ||
// The shadow config is not using ProjectDomainAttribute/Workflowattribute directly inorder to simplify the inputs. | ||
// As the same structure is being used for both ProjectDomainAttribute/Workflowattribute | ||
type TaskResourceAttrFileConfig struct { | ||
Project string `json:"project"` | ||
Domain string `json:"domain"` | ||
Workflow string `json:"workflow,omitempty"` | ||
*admin.TaskResourceAttributes | ||
} | ||
|
||
// WriteConfigToFile used for marshaling the config to a file which can then be used for update/delete | ||
func (t TaskResourceAttrFileConfig) WriteConfigToFile(fileName string) error { | ||
d, err := yaml.Marshal(t) | ||
if err != nil { | ||
return fmt.Errorf("error: %v", err) | ||
} | ||
if _, err = os.Stat(fileName); err == nil { | ||
if !cmdUtil.AskForConfirmation(fmt.Sprintf("warning file %v will be overwritten", fileName)) { | ||
return fmt.Errorf("backup the file before continuing") | ||
} | ||
} | ||
return ioutil.WriteFile(fileName, d, 0600) | ||
} | ||
|
||
// Dumps the json representation of the TaskResourceAttrFileConfig | ||
func (t TaskResourceAttrFileConfig) String() string { | ||
tj, err := json.Marshal(t) | ||
if err != nil { | ||
fmt.Println(err) | ||
return "marshaling error" | ||
} | ||
return fmt.Sprintf("%s\n", tj) | ||
} | ||
|
||
// ReadConfigFromFile used for unmarshaling the config from a file which is used for update/delete | ||
func (t *TaskResourceAttrFileConfig) ReadConfigFromFile(fileName string) error { | ||
data, err := ioutil.ReadFile(fileName) | ||
if err != nil { | ||
return fmt.Errorf("unable to read from %v yaml file", fileName) | ||
} | ||
if err = yaml.UnmarshalStrict(data, t); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// MatchableAttributeDecorator decorator over TaskResourceAttributes. Similar decorator would exist for other MatchingAttributes | ||
func (t *TaskResourceAttrFileConfig) MatchableAttributeDecorator() *admin.MatchingAttributes { | ||
return &admin.MatchingAttributes{ | ||
Target: &admin.MatchingAttributes_TaskResourceAttributes{ | ||
TaskResourceAttributes: t.TaskResourceAttributes, | ||
}, | ||
} | ||
} | ||
|
||
func (t TaskResourceAttrFileConfig) DumpTaskResourceAttr(ctx context.Context, fileName string) { | ||
// Dump empty task resource attr for editing | ||
// Write config to file if filename provided in the command | ||
if len(fileName) > 0 { | ||
// Read the config from the file and update the TaskResourceAttrFileConfig with the TaskResourceAttrConfig | ||
if err := t.WriteConfigToFile(fileName); err != nil { | ||
fmt.Printf("error dumping in file due to %v", err) | ||
logger.Warnf(ctx, "error dumping in file due to %v", err) | ||
return | ||
} | ||
fmt.Printf("wrote the config to file %v", fileName) | ||
} else { | ||
fmt.Printf("%v", t) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
flytectl/cmd/config/subcommand/task_resource_attribute_update_config.go
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,10 @@ | ||
package subcommand | ||
|
||
//go:generate pflags TaskResourceAttrUpdateConfig --default-var DefaultTaskResourceUpdateConfig | ||
|
||
// TaskResourceAttrUpdateConfig Matchable resource attributes configuration passed from command line | ||
type TaskResourceAttrUpdateConfig struct { | ||
AttrFile string `json:"attrFile" pflag:",attribute file name to be used for updating attribute for the resource type."` | ||
} | ||
|
||
var DefaultTaskResourceUpdateConfig = &TaskResourceAttrUpdateConfig{} |
46 changes: 46 additions & 0 deletions
46
flytectl/cmd/config/subcommand/taskresourceattrdeleteconfig_flags.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
124 changes: 124 additions & 0 deletions
124
flytectl/cmd/config/subcommand/taskresourceattrdeleteconfig_flags_test.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
flytectl/cmd/config/subcommand/taskresourceattrfetchconfig_flags.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.