-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from kndpio/118-load-configurations-from-loca…
…l-docker-images 118 load configurations from local docker images
- Loading branch information
Showing
10 changed files
with
435 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package configuration | ||
|
||
type Cmd struct { | ||
Apply applyCmd `cmd:"" help:"Apply Crossplane Configuration."` | ||
List listCmd `cmd:"" help:"Apply Crossplane Configuration."` | ||
Apply applyCmd `cmd:"" help:"Apply Crossplane Configuration."` | ||
List listCmd `cmd:"" help:"Apply Crossplane Configuration."` | ||
Load loadCmd `cmd:"" help:"Load Crossplane Configuration from archive."` | ||
Delete deleteCmd `cmd:"" help:"Delete Crossplane Configuration."` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package configuration | ||
|
||
import ( | ||
"bufio" | ||
"context" | ||
"os" | ||
|
||
"github.com/charmbracelet/log" | ||
cfg "github.com/kndpio/kndp/internal/configuration" | ||
"github.com/kndpio/kndp/internal/kube" | ||
"github.com/kndpio/kndp/internal/registry" | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
type loadCmd struct { | ||
Name string `arg:"" help:"Name of configuration."` | ||
Path string `help:"Path to configuration package archive."` | ||
Stdin bool `help:"Load configuration package from STDIN."` | ||
} | ||
|
||
func (c *loadCmd) Run(ctx context.Context, config *rest.Config, logger *log.Logger) error { | ||
|
||
client, err := kube.Client(config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !registry.IsLocalRegistry(ctx, client) { | ||
logger.Warn("Local registry is not installed.") | ||
return nil | ||
} | ||
|
||
cfg := cfg.Configuration{} | ||
cfg.Name = c.Name | ||
logger.Debugf("Loading image to: %s", cfg.Name) | ||
if c.Path != "" { | ||
logger.Debugf("Loading from path: %s", c.Path) | ||
err = cfg.LoadPathArchive(c.Path) | ||
if err != nil { | ||
return err | ||
} | ||
} else if c.Stdin { | ||
logger.Debug("Loading from STDIN") | ||
reader := bufio.NewReader(os.Stdin) | ||
err = cfg.LoadStdinArchive(reader) | ||
if err != nil { | ||
return err | ||
} | ||
} else { | ||
logger.Warn("Archive path or STDIN required for load configuration.") | ||
return nil | ||
} | ||
logger.Debug("Pushing to local registry") | ||
err = registry.PushLocalRegistry(ctx, cfg.Name, cfg.Image, config, logger) | ||
if err != nil { | ||
return err | ||
} | ||
logger.Infof("Image archive %s loaded to local registry.", cfg.Name) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package configuration | ||
|
||
import ( | ||
"bufio" | ||
"io" | ||
"os" | ||
|
||
"github.com/google/go-containerregistry/pkg/v1/tarball" | ||
) | ||
|
||
// Load configuration package from TAR archive path | ||
func (c *Configuration) LoadPathArchive(path string) error { | ||
image, err := tarball.ImageFromPath(path, nil) | ||
if err != nil { | ||
return err | ||
} | ||
c.Image = image | ||
return nil | ||
} | ||
|
||
// Load configuration package from STDIN | ||
func (c *Configuration) LoadStdinArchive(stream *bufio.Reader) error { | ||
stdin, err := io.ReadAll(stream) | ||
if err != nil { | ||
return err | ||
} | ||
tmpFile, err := os.CreateTemp("", "kndp-configuration-*") | ||
if err != nil { | ||
return err | ||
} | ||
tmpFile.Write(stdin) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return c.LoadPathArchive(tmpFile.Name()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.