-
Notifications
You must be signed in to change notification settings - Fork 414
Local registry #2326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Local registry #2326
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
7cf21b4
wip: local registry
lizardruss 786240c
wip: implement should rebuild
lizardruss 039cd74
wip: alternative implementation
lizardruss 659e239
test: test for local registry kubectl manifest substitution
lizardruss 5001c7e
fix: implement workaround for not being able to push using docker daemon
lizardruss 06203e9
test: remove test duplication
lizardruss 89f0a7f
test: fix builder local registry compatibility check
lizardruss 2c13aef
fix: support buildkit for local registries
lizardruss 5787f49
test: fix assertion for local registry images
lizardruss 349d390
test: fix failing tests
lizardruss 2cfd3a1
test: fix error hook expectations
lizardruss 5c55b64
fix: adjusting skip push / local registry logic
lizardruss 68e2ae1
test: turn off local registry for certain tests
lizardruss a35847e
test: test local registry with storage
lizardruss 06c487c
test: check that devImage uses local registry image
lizardruss 6b525e8
refactor: make local registry config top-level
lizardruss c4f7154
feat: add local registry push progress bar
lizardruss 230a364
fix: use correct image for ShouldRebuild() checks
lizardruss 4a12963
feat: add 'devspace cleanup local-registry' command
lizardruss b47232f
feat: add flag to prefer local registry over 'kind load'
lizardruss 5404017
refactor: local registry progress output with logger
lizardruss 5e05d34
fix: prevent using local registry when switching to/from a KinD cluster
lizardruss ad8bfd1
refactor: remove --prefer-local-registry flag
lizardruss e9c45a2
test: revert expectation changes
lizardruss 58c7e12
chore: remove unused code
lizardruss b9c6bb4
feat: apply registry configuration changes
lizardruss 6515353
chore: revert unnecessary change
lizardruss 2bceafd
refactor: minor code clean up
lizardruss 31158b0
fix: not all hooks reflect the local registry image
lizardruss 561234f
refactor: use io.Writer instead of logger for local registry progress…
lizardruss bcd2546
refactor: use server side apply and detect available registry before …
lizardruss 012cb89
refactor: use optional enabled flag to enable/disable local registry
lizardruss 65c6346
chore: clean up logic
lizardruss eb1398f
feat: add localRegistry config to devspace init output
lizardruss 6d20cdf
fix: skip push with local kubernetes with devspace build
lizardruss 69985d5
fix: skip local registry when using minikube
lizardruss 5e850f7
fix: add logging prefix for local registry
lizardruss 0b325af
fix: 'devspace cleanup local-regitry' check for local registry before…
lizardruss 4066218
fix: use resolved image in errors / log messages
lizardruss 35682f1
fix: add enabled flag to localRegistry init output
lizardruss 724d8d4
fix: log a warning when the local registry is skipped due to Minikube
lizardruss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,171 @@ | ||
| package cleanup | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/loft-sh/devspace/cmd/flags" | ||
| "github.com/loft-sh/devspace/pkg/devspace/build/registry" | ||
| "github.com/loft-sh/devspace/pkg/devspace/kubectl" | ||
| "github.com/loft-sh/devspace/pkg/util/factory" | ||
| "github.com/loft-sh/devspace/pkg/util/message" | ||
| "github.com/loft-sh/devspace/pkg/util/survey" | ||
| "github.com/sirupsen/logrus" | ||
| kerrors "k8s.io/apimachinery/pkg/api/errors" | ||
| v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
||
| "github.com/pkg/errors" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| type localRegistryCmd struct { | ||
| *flags.GlobalFlags | ||
| } | ||
|
|
||
| func newLocalRegistryCmd(f factory.Factory, globalFlags *flags.GlobalFlags) *cobra.Command { | ||
| cmd := &localRegistryCmd{GlobalFlags: globalFlags} | ||
|
|
||
| localRegistryCmd := &cobra.Command{ | ||
| Use: "local-registry", | ||
| Short: "Deletes the local image registry", | ||
| Long: ` | ||
| ####################################################### | ||
| ######### devspace cleanup local-registry ############# | ||
| ####################################################### | ||
| Deletes the local image registry | ||
| ####################################################### | ||
| `, | ||
| Args: cobra.NoArgs, | ||
| RunE: func(cobraCmd *cobra.Command, args []string) error { | ||
| return cmd.RunCleanupLocalRegistry(f, cobraCmd, args) | ||
| }} | ||
|
|
||
| return localRegistryCmd | ||
| } | ||
|
|
||
| // RunCleanupLocalRegistry executes the cleanup local-registry command logic | ||
| func (cmd *localRegistryCmd) RunCleanupLocalRegistry(f factory.Factory, cobraCmd *cobra.Command, args []string) error { | ||
| ctx := context.Background() | ||
| log := f.GetLog() | ||
|
|
||
| // set config root | ||
| configLoader, err := f.NewConfigLoader(cmd.ConfigPath) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| configExists, err := configLoader.SetDevSpaceRoot(log) | ||
| if err != nil { | ||
| return err | ||
| } else if !configExists { | ||
| return errors.New(message.ConfigNotFound) | ||
| } | ||
|
|
||
| // create kubectl client | ||
| client, err := f.NewKubeClientFromContext(cmd.KubeContext, cmd.Namespace) | ||
| if err != nil { | ||
| log.Warnf("Unable to create new kubectl client: %v", err) | ||
| log.WriteString(logrus.WarnLevel, "\n") | ||
| client = nil | ||
| } | ||
|
|
||
| // load generated config | ||
| localCache, err := configLoader.LoadLocalCache() | ||
| if err != nil { | ||
| return errors.Errorf("error loading local cache: %v", err) | ||
| } | ||
|
|
||
| if client != nil { | ||
| // If the current kube context or namespace is different than old, | ||
| // show warnings and reset kube client if necessary | ||
| client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.SwitchContext, false, log) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| // load config | ||
| configInterface, err := configLoader.LoadWithCache(ctx, localCache, client, cmd.ToConfigOptions(), log) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // clean up registry according to options | ||
| config := configInterface.Config() | ||
| options := registry.NewDefaultOptions(). | ||
| WithNamespace(client.Namespace()). | ||
| WithLocalRegistryConfig(config.LocalRegistry) | ||
|
|
||
| hasStatefulSet := true | ||
| _, err = client.KubeClient().AppsV1().StatefulSets(options.Namespace).Get(ctx, options.Name, v1.GetOptions{}) | ||
| if err != nil { | ||
| if kerrors.IsNotFound(err) { | ||
| hasStatefulSet = false | ||
| } else { | ||
| return errors.Wrap(err, "clean up statefulset") | ||
| } | ||
| } | ||
|
|
||
| hasDeployment := true | ||
| _, err = client.KubeClient().AppsV1().Deployments(options.Namespace).Get(ctx, options.Name, v1.GetOptions{}) | ||
| if err != nil { | ||
| if kerrors.IsNotFound(err) { | ||
| hasDeployment = false | ||
| } else { | ||
| return errors.Wrap(err, "clean up statefulset") | ||
| } | ||
| } | ||
|
|
||
| hasService := true | ||
| _, err = client.KubeClient().CoreV1().Services(options.Namespace).Get(ctx, options.Name, v1.GetOptions{}) | ||
| if err != nil { | ||
| if kerrors.IsNotFound(err) { | ||
| hasService = false | ||
| } else { | ||
| return errors.Wrap(err, "clean up statefulset") | ||
| } | ||
| } | ||
|
|
||
| if !hasStatefulSet && !hasDeployment && !hasService { | ||
| log.Donef("No local registry found.") | ||
| return nil | ||
| } | ||
|
|
||
| // prompt user since this is a destructive action | ||
| cleanupAnswer, err := log.Question(&survey.QuestionOptions{ | ||
| Question: "This will delete your local registry and all the images it contains. Do you wish to continue?", | ||
| Options: []string{ | ||
| "Yes", | ||
| "No", | ||
| }, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if cleanupAnswer == "No" { | ||
| return nil | ||
| } | ||
|
|
||
| if hasStatefulSet { | ||
| err = client.KubeClient().AppsV1().StatefulSets(options.Namespace).Delete(ctx, options.Name, v1.DeleteOptions{}) | ||
| if err != nil && !kerrors.IsNotFound(err) { | ||
| return errors.Wrap(err, "clean up statefulset") | ||
| } | ||
| } | ||
|
|
||
| if hasDeployment { | ||
| err = client.KubeClient().AppsV1().Deployments(options.Namespace).Delete(ctx, options.Name, v1.DeleteOptions{}) | ||
| if err != nil && !kerrors.IsNotFound(err) { | ||
| return errors.Wrap(err, "clean up deployment") | ||
| } | ||
| } | ||
|
|
||
| if hasService { | ||
| err = client.KubeClient().CoreV1().Services(options.Namespace).Delete(ctx, options.Name, v1.DeleteOptions{}) | ||
| if err != nil && !kerrors.IsNotFound(err) { | ||
| return errors.Wrap(err, "clean up service") | ||
| } | ||
| } | ||
|
|
||
| log.Donef("Successfully cleaned up local registry") | ||
| return nil | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,8 @@ | ||
| package localregistry | ||
|
|
||
| import "github.com/onsi/ginkgo" | ||
|
|
||
| // DevSpaceDescribe annotates the test with the label. | ||
| func DevSpaceDescribe(text string, body func()) bool { | ||
| return ginkgo.Describe("[localregistry] "+text, body) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.