LoadWithParser loads the config with the given parser
(ctx context.Context, localCache localcache.Cache, client kubectl.Client, parser Parser, options *ConfigOptions, log log.Logger)
| 112 | |
| 113 | // LoadWithParser loads the config with the given parser |
| 114 | func (l *configLoader) LoadWithParser(ctx context.Context, localCache localcache.Cache, client kubectl.Client, parser Parser, options *ConfigOptions, log log.Logger) (_ config.Config, err error) { |
| 115 | if localCache == nil { |
| 116 | localCache, err = l.LoadLocalCache() |
| 117 | if err != nil { |
| 118 | return nil, err |
| 119 | } |
| 120 | } |
| 121 | if options == nil { |
| 122 | options = &ConfigOptions{} |
| 123 | } |
| 124 | |
| 125 | defer func() { |
| 126 | if err != nil { |
| 127 | pluginErr := plugin.ExecutePluginHookWithContext(map[string]interface{}{"ERROR": err, "LOAD_PATH": l.absConfigPath}, "config.errorLoad", "error:loadConfig") |
| 128 | if pluginErr != nil { |
| 129 | log.Warnf("Error executing plugin hook: %v", pluginErr) |
| 130 | return |
| 131 | } |
| 132 | } |
| 133 | }() |
| 134 | |
| 135 | // call plugin hook |
| 136 | pluginErr := plugin.ExecutePluginHookWithContext(map[string]interface{}{"LOAD_PATH": l.absConfigPath}, "config.beforeLoad", "before:loadConfig") |
| 137 | if pluginErr != nil { |
| 138 | return nil, pluginErr |
| 139 | } |
| 140 | |
| 141 | // load the raw data |
| 142 | data, err := l.LoadRaw() |
| 143 | if err != nil { |
| 144 | return nil, err |
| 145 | } |
| 146 | |
| 147 | // make sure name is in config |
| 148 | name := options.OverrideName |
| 149 | if name == "" { |
| 150 | var ok bool |
| 151 | name, ok = data["name"].(string) |
| 152 | if !ok { |
| 153 | return nil, fmt.Errorf("name is missing in %s", filepath.Base(l.absConfigPath)) |
| 154 | } |
| 155 | } else { |
| 156 | data["name"] = options.OverrideName |
| 157 | } |
| 158 | |
| 159 | // validate name |
| 160 | if encoding.IsUnsafeName(name) { |
| 161 | return nil, fmt.Errorf("DevSpace config has an invalid name '%s', must match regex %s", name, encoding.UnsafeNameRegEx.String()) |
| 162 | } |
| 163 | |
| 164 | // set name to context |
| 165 | ctx = values.WithName(ctx, name) |
| 166 | |
| 167 | // create remote cache |
| 168 | var remoteCache remotecache.Cache |
| 169 | if client != nil { |
| 170 | remoteCache, err = remotecache.NewCacheLoader(name).Load(ctx, client) |
| 171 | if err != nil { |