From 68e5c13fb8f3623cc11d7203c93c5387cf758112 Mon Sep 17 00:00:00 2001 From: Sergii Leshchenko Date: Wed, 31 Mar 2021 18:05:07 +0300 Subject: [PATCH] fixup! Finalize workspace -> devworkspace renaming --- generator/main.go | 2 +- pkg/utils/overriding/keys.go | 4 ++-- pkg/utils/overriding/merging.go | 34 ++++++++++++++++----------------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/generator/main.go b/generator/main.go index 7632facbb..d4c2a77d3 100644 --- a/generator/main.go +++ b/generator/main.go @@ -110,7 +110,7 @@ func main() { cmd := &cobra.Command{ Use: "generator", - Short: "Generates various types of files from the `workspace` K8S API source code.", + Short: "Generates various types of files from the `workspaces` K8S API source code.", Long: "Generates additional GO source files (for devfile overriding, union support, deep-copy), K8S CRD YAML files and Json Schemas from the from the `workspaces` K8S API source code.", Example: ` # Generate Plugin Overrides based on the workspaces/v1alpha2 K8S API diff --git a/pkg/utils/overriding/keys.go b/pkg/utils/overriding/keys.go index 27c7254c4..aa25dc472 100644 --- a/pkg/utils/overriding/keys.go +++ b/pkg/utils/overriding/keys.go @@ -1,7 +1,7 @@ package overriding import ( - devworkspaces "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" + dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" "github.com/hashicorp/go-multierror" "k8s.io/apimachinery/pkg/util/sets" ) @@ -14,7 +14,7 @@ type checkFn func(elementType string, keysSets []sets.String) []error // For each type of top-level list, the `keysSets` argument that will be passed to the `doCheck` function // contains the the key sets that correspond to the `toplevelListContainers` passed to this method, // in the same order. -func checkKeys(doCheck checkFn, toplevelListContainers ...devworkspaces.TopLevelListContainer) error { +func checkKeys(doCheck checkFn, toplevelListContainers ...dw.TopLevelListContainer) error { var errors *multierror.Error // intermediate storage for the conversion []map[string]KeyedList -> map[string][]sets.String diff --git a/pkg/utils/overriding/merging.go b/pkg/utils/overriding/merging.go index 7db05339d..72a1e5093 100644 --- a/pkg/utils/overriding/merging.go +++ b/pkg/utils/overriding/merging.go @@ -5,7 +5,7 @@ import ( "reflect" "strings" - devworkspaces "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" + dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" "k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/yaml" @@ -21,11 +21,11 @@ import ( // The result is a transformed `DevWorkspaceTemplateSpec` object, that does not contain any `plugin` component // (since they are expected to be provided as flattened overridden devfiles in the arguments) func MergeDevWorkspaceTemplateSpec( - mainContent *devworkspaces.DevWorkspaceTemplateSpecContent, - parentFlattenedContent *devworkspaces.DevWorkspaceTemplateSpecContent, - pluginFlattenedContents ...*devworkspaces.DevWorkspaceTemplateSpecContent) (*devworkspaces.DevWorkspaceTemplateSpecContent, error) { + mainContent *dw.DevWorkspaceTemplateSpecContent, + parentFlattenedContent *dw.DevWorkspaceTemplateSpecContent, + pluginFlattenedContents ...*dw.DevWorkspaceTemplateSpecContent) (*dw.DevWorkspaceTemplateSpecContent, error) { - allContents := []*devworkspaces.DevWorkspaceTemplateSpecContent{} + allContents := []*dw.DevWorkspaceTemplateSpecContent{} if parentFlattenedContent != nil { allContents = append(allContents, parentFlattenedContent) } @@ -52,12 +52,12 @@ func MergeDevWorkspaceTemplateSpec( } } - result := devworkspaces.DevWorkspaceTemplateSpecContent{} + result := dw.DevWorkspaceTemplateSpecContent{} // Merge top-level lists (Commands, Projects, Components, etc ...) topLevelListsNames := result.GetToplevelLists() - topLevelListsByContent := []devworkspaces.TopLevelLists{} + topLevelListsByContent := []dw.TopLevelLists{} for _, content := range allContents { topLevelListsByContent = append(topLevelListsByContent, content.GetToplevelLists()) } @@ -78,7 +78,7 @@ func MergeDevWorkspaceTemplateSpec( keyedList := toplevelLists[toplevelListName] for _, keyed := range keyedList { if content == mainContent { - if component, isComponent := keyed.(devworkspaces.Component); isComponent && + if component, isComponent := keyed.(dw.Component); isComponent && component.Plugin != nil { continue } @@ -98,7 +98,7 @@ func MergeDevWorkspaceTemplateSpec( for _, content := range allContents { if content.Events != nil { if result.Events == nil { - result.Events = &devworkspaces.Events{} + result.Events = &dw.Events{} } preStartCommands = preStartCommands.Union(sets.NewString(content.Events.PreStart...)) postStartCommands = postStartCommands.Union(sets.NewString(content.Events.PostStart...)) @@ -126,13 +126,13 @@ func MergeDevWorkspaceTemplateSpec( // // The result is a transformed `DevfileWorkspaceTemplateSpec` object, that does not contain any `plugin` component // (since they are expected to be provided as flattened overridden devfiles in the arguments) -func MergeDevWorkspaceTemplateSpecBytes(originalBytes []byte, flattenedParentBytes []byte, flattenPluginsBytes ...[]byte) (*devworkspaces.DevWorkspaceTemplateSpecContent, error) { +func MergeDevWorkspaceTemplateSpecBytes(originalBytes []byte, flattenedParentBytes []byte, flattenPluginsBytes ...[]byte) (*dw.DevWorkspaceTemplateSpecContent, error) { originalJson, err := yaml.ToJSON(originalBytes) if err != nil { return nil, err } - original := devworkspaces.DevWorkspaceTemplateSpecContent{} + original := dw.DevWorkspaceTemplateSpecContent{} err = json.Unmarshal(originalJson, &original) if err != nil { return nil, err @@ -143,20 +143,20 @@ func MergeDevWorkspaceTemplateSpecBytes(originalBytes []byte, flattenedParentByt return nil, err } - flattenedParent := devworkspaces.DevWorkspaceTemplateSpecContent{} + flattenedParent := dw.DevWorkspaceTemplateSpecContent{} err = json.Unmarshal(flattenedParentJson, &flattenedParent) if err != nil { return nil, err } - flattenedPlugins := []*devworkspaces.DevWorkspaceTemplateSpecContent{} + flattenedPlugins := []*dw.DevWorkspaceTemplateSpecContent{} for _, flattenedPluginBytes := range flattenPluginsBytes { flattenedPluginJson, err := yaml.ToJSON(flattenedPluginBytes) if err != nil { return nil, err } - flattenedPlugin := devworkspaces.DevWorkspaceTemplateSpecContent{} + flattenedPlugin := dw.DevWorkspaceTemplateSpecContent{} err = json.Unmarshal(flattenedPluginJson, &flattenedPlugin) if err != nil { return nil, err @@ -167,7 +167,7 @@ func MergeDevWorkspaceTemplateSpecBytes(originalBytes []byte, flattenedParentByt return MergeDevWorkspaceTemplateSpec(&original, &flattenedParent, flattenedPlugins...) } -func ensureNoConflictWithParent(mainContent *devworkspaces.DevWorkspaceTemplateSpecContent, parentflattenedContent *devworkspaces.DevWorkspaceTemplateSpecContent) error { +func ensureNoConflictWithParent(mainContent *dw.DevWorkspaceTemplateSpecContent, parentflattenedContent *dw.DevWorkspaceTemplateSpecContent) error { return checkKeys(func(elementType string, keysSets []sets.String) []error { mainKeys := keysSets[0] parentOrPluginKeys := keysSets[1] @@ -183,7 +183,7 @@ func ensureNoConflictWithParent(mainContent *devworkspaces.DevWorkspaceTemplateS mainContent, parentflattenedContent) } -func ensureNoConflictsWithPlugins(mainContent *devworkspaces.DevWorkspaceTemplateSpecContent, pluginFlattenedContents ...*devworkspaces.DevWorkspaceTemplateSpecContent) error { +func ensureNoConflictsWithPlugins(mainContent *dw.DevWorkspaceTemplateSpecContent, pluginFlattenedContents ...*dw.DevWorkspaceTemplateSpecContent) error { getPluginKey := func(pluginIndex int) string { index := 0 for _, comp := range mainContent.Components { @@ -197,7 +197,7 @@ func ensureNoConflictsWithPlugins(mainContent *devworkspaces.DevWorkspaceTemplat return "unknown" } - allSpecs := []devworkspaces.TopLevelListContainer{mainContent} + allSpecs := []dw.TopLevelListContainer{mainContent} for _, pluginFlattenedContent := range pluginFlattenedContents { allSpecs = append(allSpecs, pluginFlattenedContent) }