Skip to content

Commit

Permalink
fixup! Finalize workspace -> devworkspace renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
sleshchenko committed Mar 31, 2021
1 parent 9aff1eb commit 68e5c13
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/overriding/keys.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand All @@ -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
Expand Down
34 changes: 17 additions & 17 deletions pkg/utils/overriding/merging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
Expand All @@ -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())
}
Expand All @@ -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
}
Expand All @@ -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...))
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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 {
Expand All @@ -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)
}
Expand Down

0 comments on commit 68e5c13

Please sign in to comment.