Skip to content

Commit

Permalink
feat: use dedicated ingress maps
Browse files Browse the repository at this point in the history
  • Loading branch information
rainest committed Nov 22, 2023
1 parent 80251d4 commit 1113303
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions pkg/core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,35 @@ func Run(_ context.Context, c *Config, logger logr.Logger) error {
// Keep a copy of the original to diff later.
transformed = orig

remaps := map[string]mapFunc{
kongRemaps := map[string]mapFunc{
controllerPrefix: getControllerKeys,
gatewayPrefix: getGatewayKeys,
}

ingressRemaps := map[string]mapFunc{
controllerPrefix: getIngressControllerKeys,
gatewayPrefix: getIngressGatewayKeys,
}

for _, prefix := range []string{controllerPrefix, gatewayPrefix} {
var remaps map[string]mapFunc
if c.SourceChart == ingressChart {
remaps = ingressRemaps
} else if c.SourceChart == ingressChart {
remaps = kongRemaps
} else {
return fmt.Errorf("unknown source chart: %s", c.SourceChart)
}
for start, end := range remaps[prefix]() {
fullStart := start
if c.SourceChart == ingressChart {
fullStart = fmt.Sprintf("%s.%s", prefix, start)
}
transformed, err = Move(fullStart, end, transformed)
transformed, err = Move(start, end, transformed)
if err != nil {
logger.Error(err, "migration failed")
}
// not immediately clear why, but attempting to move AND delete within Move (the contents of Delete originally
// followed the sjson.SetBytes() call and error check) resulted in it deleting both the old and new key.
// Presumably something about how it addresses the values internally. Returning and then deleting avoids this,
// since we have a new []byte to work with.
transformed, err = Delete(fullStart, transformed)
transformed, err = Delete(start, transformed)
if err != nil {
logger.Error(err, "cleanup failed")
}
Expand Down

0 comments on commit 1113303

Please sign in to comment.