-
Notifications
You must be signed in to change notification settings - Fork 410
Skip local registry use for vclusters on local kubernetes clusters #2390
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
FabianKramm
merged 1 commit into
devspace-sh:main
from
lizardruss:local-registry-vclusters
Oct 24, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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 |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import ( | |
| "fmt" | ||
| "io" | ||
| "net/http" | ||
| "strings" | ||
|
|
||
| "github.com/docker/docker/pkg/jsonmessage" | ||
| "github.com/google/go-containerregistry/pkg/authn" | ||
|
|
@@ -14,7 +15,8 @@ import ( | |
| "github.com/google/go-containerregistry/pkg/v1/remote" | ||
| "github.com/google/go-containerregistry/pkg/v1/remote/transport" | ||
| "github.com/loft-sh/devspace/pkg/devspace/config/versions/latest" | ||
| devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context" | ||
| dockerclient "github.com/loft-sh/devspace/pkg/devspace/docker" | ||
| "github.com/loft-sh/devspace/pkg/devspace/kubectl" | ||
| corev1 "k8s.io/api/core/v1" | ||
| ) | ||
|
|
||
|
|
@@ -29,7 +31,7 @@ func HasPushPermission(image *latest.Image) bool { | |
| } | ||
|
|
||
| func IsLocalRegistryFallback(config *latest.Config) bool { | ||
| return config.LocalRegistry == nil || (config.LocalRegistry != nil || config.LocalRegistry.Enabled == nil) | ||
| return config.LocalRegistry == nil || (config.LocalRegistry != nil && config.LocalRegistry.Enabled == nil) | ||
| } | ||
|
|
||
| func IsLocalRegistryEnabled(config *latest.Config) bool { | ||
|
|
@@ -67,13 +69,13 @@ func IsImageAvailableRemotely(ctx context.Context, imageName string) (bool, erro | |
| return image != nil, nil | ||
| } | ||
|
|
||
| func CopyImageToRemote(ctx context.Context, imageName string, writer io.Writer) error { | ||
| func CopyImageToRemote(ctx context.Context, client dockerclient.Client, imageName string, writer io.Writer) error { | ||
| ref, err := name.ParseReference(imageName) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| image, err := daemon.Image(ref, daemon.WithContext(ctx)) | ||
| image, err := daemon.Image(ref, daemon.WithContext(ctx), daemon.WithClient(client.DockerAPIClient())) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This update allows the local registry push to work with either the local docker daemon, or the Minikube docker daemon. |
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -118,17 +120,26 @@ func CopyImageToRemote(ctx context.Context, imageName string, writer io.Writer) | |
| return <-errChan | ||
| } | ||
|
|
||
| func UseMinikubeDocker(ctx devspacecontext.Context, image *latest.Image) bool { | ||
| // preferMinikube := false | ||
| var preferMinikube *bool | ||
| func UseLocalRegistry(client kubectl.Client, config *latest.Config, skipPush bool) bool { | ||
| if skipPush { | ||
| return false | ||
| } | ||
|
|
||
| if image.Docker != nil { | ||
| preferMinikube = image.Docker.PreferMinikube | ||
| if client == nil { | ||
| return false | ||
| } | ||
|
|
||
| if image.BuildKit != nil { | ||
| preferMinikube = image.BuildKit.PreferMinikube | ||
| if !IsLocalRegistryFallback(config) { | ||
| return IsLocalRegistryEnabled(config) | ||
| } | ||
|
|
||
| return ctx.KubeClient() != nil && ctx.KubeClient().CurrentContext() == "minikube" && (preferMinikube == nil || *preferMinikube) | ||
| context := client.CurrentContext() | ||
|
|
||
| // Determine if this is a vcluster | ||
| isVClusterContext := strings.HasPrefix(context, "vcluster_") | ||
|
|
||
| // Determine if this is a local kubernetes cluster | ||
| isLocalKubernetes := kubectl.IsLocalKubernetes(context) | ||
|
|
||
| return !isLocalKubernetes && !(isVClusterContext && isLocalKubernetes) | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can bring back this edge case if desired, but it was somewhat unexpected to have
localRegistry.enabled = trueand it still not be used because of minikube.This did require using a docker client configured for the minikube environment to work, see later comments.