diff --git a/go.sum b/go.sum index 2a1dde2a..dee174d3 100644 --- a/go.sum +++ b/go.sum @@ -415,15 +415,11 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220906165534-d0df966e6959/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= -golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220411215600-e5f449aeb171/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= -golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/internal/myks/sync_vendir.go b/internal/myks/sync_vendir.go index 29a52874..943d4be5 100644 --- a/internal/myks/sync_vendir.go +++ b/internal/myks/sync_vendir.go @@ -94,7 +94,7 @@ func (v *VendirSyncer) doSync(a *Application, vendirSecrets string) error { return err } - for dirPath, cacheName := range linksMap { + for contentPath, cacheName := range linksMap { cacheDir := a.expandVendirCache(cacheName.(string)) vendirConfigPath := filepath.Join(cacheDir, a.e.g.VendirConfigFileName) vendirLockPath := filepath.Join(cacheDir, a.e.g.VendirLockFileName) @@ -102,7 +102,7 @@ func (v *VendirSyncer) doSync(a *Application, vendirSecrets string) error { log.Error().Err(err).Msg(a.Msg(v.getStepName(), "Vendir sync failed")) return err } - if err := v.linkVendorToCache(a, dirPath, cacheName.(string)); err != nil { + if err := v.linkVendorToCache(a, contentPath, cacheName.(string)); err != nil { log.Error().Err(err).Msg(a.Msg(v.getStepName(), "Unable to create link to cache")) return err } @@ -157,34 +157,29 @@ func (v *VendirSyncer) extractCacheItems(a *Application) error { return err } - dirToCacheMap := map[string]string{} + vendorDirToCacheMap := map[string]string{} for _, dir := range vendirConfig["directories"].([]interface{}) { dirMap := dir.(map[string]interface{}) - dirPath := dirMap["path"].(string) contents := dirMap["contents"].([]interface{}) - if len(contents) == 0 { - log.Warn().Str("directory", dirPath).Msg(a.Msg(v.getStepName(), "No contents found in vendir config directory")) - continue - } else if len(contents) > 1 { - log.Warn().Str("directory", dirPath).Msg(a.Msg(v.getStepName(), "Multiple contents found in vendir config directory")) - return errors.New("multiple contents are not supported in vendir config directory") - } - contentMap := contents[0].(map[string]interface{}) - cacheName, err := genCacheName(contentMap) - if err != nil { - return err - } - dirToCacheMap[dirPath] = cacheName - cacheDir := a.expandVendirCache(cacheName) - // FIXME: Possible race condition if multiple applications are running in parallel - if err = v.saveCacheVendirConfig(a, cacheName, buildCacheVendirConfig(cacheDir, vendirConfig, dirMap)); err != nil { - return err + for _, content := range contents { + vendorDirPath := filepath.Join(dirMap["path"].(string), content.(map[string]interface{})["path"].(string)) + contentMap := content.(map[string]interface{}) + cacheName, err := genCacheName(contentMap) + if err != nil { + return err + } + vendorDirToCacheMap[vendorDirPath] = cacheName + cacheDir := a.expandVendirCache(cacheName) + // FIXME: Possible race condition if multiple applications are running in parallel + if err = v.saveCacheVendirConfig(a, cacheName, buildCacheVendirConfig(cacheDir, vendirConfig, dirMap, contentMap)); err != nil { + return err + } } } - return v.saveLinksMap(a, dirToCacheMap) + return v.saveLinksMap(a, vendorDirToCacheMap) } func (a *Application) getCacheVendirConfigPath(cacheName string) string { @@ -205,7 +200,7 @@ func (v *VendirSyncer) saveCacheVendirConfig(a *Application, cacheName string, v return nil } -func buildCacheVendirConfig(cacheDir string, vendirConfig, vendirDirConfig map[string]interface{}) map[string]interface{} { +func buildCacheVendirConfig(cacheDir string, vendirConfig, vendirDirConfig, vendirContentConfig map[string]interface{}) map[string]interface{} { knownKeys := []string{"apiVersion", "kind", "minimumRequiredVersion"} newVendirConfig := map[string]interface{}{} for _, key := range knownKeys { @@ -214,15 +209,15 @@ func buildCacheVendirConfig(cacheDir string, vendirConfig, vendirDirConfig map[s } } - // Enable lazy mode by default - contentMap := vendirDirConfig["contents"].([]interface{})[0].(map[string]interface{}) - if _, ok := contentMap["lazy"]; !ok { - contentMap["lazy"] = true - } - + newDirConfig := map[string]interface{}{} // TODO: move "data" to the Globe config or to a constant - vendirDirConfig["path"] = filepath.Join(cacheDir, "data") - newVendirConfig["directories"] = []interface{}{vendirDirConfig} + newDirConfig["path"] = filepath.Join(cacheDir, "data") + newDirConfig["permissions"] = vendirDirConfig["permissions"] + + vendirContentConfig["path"] = "." + + newDirConfig["contents"] = []interface{}{vendirContentConfig} + newVendirConfig["directories"] = []interface{}{newDirConfig} return newVendirConfig }