Run executes the command logic
(f factory.Factory)
| 115 | |
| 116 | // Run executes the command logic |
| 117 | func (cmd *SyncCmd) Run(f factory.Factory) error { |
| 118 | if cmd.Ctx == nil { |
| 119 | var cancelFn context.CancelFunc |
| 120 | cmd.Ctx, cancelFn = context.WithCancel(context.Background()) |
| 121 | defer cancelFn() |
| 122 | } |
| 123 | |
| 124 | // Switch working directory |
| 125 | if cmd.ConfigPath != "" { |
| 126 | _, err := os.Stat(cmd.ConfigPath) |
| 127 | if err != nil { |
| 128 | return errors.Errorf("--config is specified, but config %s cannot be loaded: %v", cmd.GlobalFlags.ConfigPath, err) |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | // Load generated config if possible |
| 133 | var err error |
| 134 | var localCache localcache.Cache |
| 135 | logger := f.GetLog() |
| 136 | configOptions := cmd.ToConfigOptions() |
| 137 | configLoader, err := f.NewConfigLoader(cmd.ConfigPath) |
| 138 | if err != nil { |
| 139 | return err |
| 140 | } |
| 141 | if configLoader.Exists() { |
| 142 | if cmd.GlobalFlags.ConfigPath != "" { |
| 143 | configExists, err := configLoader.SetDevSpaceRoot(logger) |
| 144 | if err != nil { |
| 145 | return err |
| 146 | } else if !configExists { |
| 147 | return errors.New(message.ConfigNotFound) |
| 148 | } |
| 149 | |
| 150 | localCache, err = configLoader.LoadLocalCache() |
| 151 | if err != nil { |
| 152 | return err |
| 153 | } |
| 154 | } else { |
| 155 | logger.Warnf("If you want to use the sync paths from `devspace.yaml`, use the `DEVSPACE_CONFIG=devspace.yaml` environment variable for this command.") |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | // Get config with adjusted cluster config |
| 160 | client, err := f.NewKubeClientFromContext(cmd.KubeContext, cmd.Namespace) |
| 161 | if err != nil { |
| 162 | return errors.Wrap(err, "new kube client") |
| 163 | } |
| 164 | |
| 165 | // If the current kube context or namespace is different from old, |
| 166 | // show warnings and reset kube client if necessary |
| 167 | client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.SwitchContext, false, logger) |
| 168 | if err != nil { |
| 169 | return err |
| 170 | } |
| 171 | |
| 172 | var configInterface config.Config |
| 173 | if configLoader.Exists() && cmd.GlobalFlags.ConfigPath != "" { |
| 174 | configInterface, err = configLoader.LoadWithCache(context.Background(), localCache, client, configOptions, logger) |
no test coverage detected