-
Notifications
You must be signed in to change notification settings - Fork 280
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
[credential provider] Add a flag mirrorMapping #6846
[credential provider] Add a flag mirrorMapping #6846
Conversation
return image, "" | ||
} | ||
|
||
// processMirrorMapping input format: "--mirror-mapping=aaa:bbb,ccc:ddd" |
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.
how to handle "aaa:bbb,aaa:ccc"?
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.
Current logic takes aaa:ccc
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.
so this PR only supports one mirror mapping?
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.
No, it supports multiple.
Bin's question is how to handle two mappings with the same source registry. The logic is that the latter one takes effect.
8c0a9e2
to
3d563f5
Compare
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.
pls also add detailed description in the PR for mirror-mapping=mcr.microsoft.com:xxx.azurecr.io
mapping
cmd/acr-credential-provider/main.go
Outdated
@@ -60,6 +63,9 @@ func main() { | |||
logs.InitLogs() | |||
defer logs.FlushLogs() | |||
|
|||
// Flags | |||
command.Flags().StringVarP(&mirrorMappingStr, "mirror-mapping", "m", "", "mirror mapping to use") |
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.
this flag value is defined after it's used in L50, then how could external user use defined flag to override this?
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.
I think as long as it is before command.Execute()
then it is ok.
Please check the CCM code. You can see cmd is defined first, then flags.
cloud-provider-azure/cmd/cloud-controller-manager/app/controllermanager.go
Lines 79 to 159 in 9eb8173
cmd := &cobra.Command{ | |
Use: "cloud-controller-manager", | |
Long: `The Cloud controller manager is a daemon that embeds the cloud specific control loops shipped with Kubernetes.`, | |
Run: func(cmd *cobra.Command, _ []string) { | |
verflag.PrintAndExitIfRequested("Cloud Provider Azure") | |
cliflag.PrintFlags(cmd.Flags()) | |
c, err := s.Config(KnownControllers(), ControllersDisabledByDefault.List(), controllerAliases) | |
if err != nil { | |
klog.Errorf("Run: failed to configure cloud controller manager: %v", err) | |
os.Exit(1) | |
} | |
healthHandler, err := StartHTTPServer(c.Complete(), wait.NeverStop) | |
if err != nil { | |
klog.Errorf("Run: railed to start HTTP server: %v", err) | |
os.Exit(1) | |
} | |
if c.ComponentConfig.Generic.LeaderElection.LeaderElect { | |
// Identity used to distinguish between multiple cloud controller manager instances | |
id, err := os.Hostname() | |
if err != nil { | |
klog.Errorf("Run: failed to get host name: %v", err) | |
os.Exit(1) | |
} | |
// add a uniquifier so that two processes on the same host don't accidentally both become active | |
id = id + "_" + string(uuid.NewUUID()) | |
// Lock required for leader election | |
rl, err := resourcelock.NewFromKubeconfig(c.ComponentConfig.Generic.LeaderElection.ResourceLock, | |
c.ComponentConfig.Generic.LeaderElection.ResourceNamespace, | |
c.ComponentConfig.Generic.LeaderElection.ResourceName, | |
resourcelock.ResourceLockConfig{ | |
Identity: id, | |
EventRecorder: c.EventRecorder, | |
}, | |
c.Kubeconfig, | |
c.ComponentConfig.Generic.LeaderElection.RenewDeadline.Duration) | |
if err != nil { | |
klog.Fatalf("error creating lock: %v", err) | |
} | |
// Try and become the leader and start cloud controller manager loops | |
var electionChecker *leaderelection.HealthzAdaptor | |
if c.ComponentConfig.Generic.LeaderElection.LeaderElect { | |
electionChecker = leaderelection.NewLeaderHealthzAdaptor(time.Second * 20) | |
} | |
leaderelection.RunOrDie(context.TODO(), leaderelection.LeaderElectionConfig{ | |
Lock: rl, | |
LeaseDuration: c.ComponentConfig.Generic.LeaderElection.LeaseDuration.Duration, | |
RenewDeadline: c.ComponentConfig.Generic.LeaderElection.RenewDeadline.Duration, | |
RetryPeriod: c.ComponentConfig.Generic.LeaderElection.RetryPeriod.Duration, | |
Callbacks: leaderelection.LeaderCallbacks{ | |
OnStartedLeading: RunWrapper(s, c, healthHandler), | |
OnStoppedLeading: func() { | |
klog.ErrorS(nil, "leaderelection lost") | |
klog.FlushAndExit(klog.ExitFlushTimeout, 1) | |
}, | |
}, | |
WatchDog: electionChecker, | |
Name: "cloud-controller-manager", | |
}) | |
panic("unreachable") | |
} | |
RunWrapper(s, c, healthHandler)(context.TODO()) | |
panic("unreachable") | |
}, | |
} | |
fs := cmd.Flags() | |
namedFlagSets := s.Flags(KnownControllers(), ControllersDisabledByDefault.List()) | |
verflag.AddFlags(namedFlagSets.FlagSet("global")) | |
globalflag.AddGlobalFlags(namedFlagSets.FlagSet("global"), cmd.Name()) | |
for _, f := range namedFlagSets.FlagSets { | |
fs.AddFlagSet(f) | |
} |
return image, "" | ||
} | ||
|
||
// processMirrorMapping input format: "--mirror-mapping=aaa:bbb,ccc:ddd" |
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.
so this PR only supports one mirror mapping?
Username: username, | ||
Password: password, | ||
} | ||
if sourceloginServer != "" { | ||
response.Auth[sourceloginServer] = v1.AuthConfig{ |
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.
you will add auth for both sourceloginServer
and targetloginServer
, is that necessary?
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.
Yes. I think it does no harm, right.
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.
then you will use password pull the mcr image, not sure whether that has side effect, in this case, only targetloginServer
needs password?
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.
When mirror mapping is used, in this case, sourceLoginServer
is like MCR and targetloginServer
is like ACR. So, it is the sourceloginServer
needs password.
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.
mcr + acr auth is a MUST, additional auth should bring no hard.
kubelet will send mcr image + acr auth to containerd to pull mcr image, and containerd will mirror the mcr image to acr through registry host, and finally pull mcr image from acr server.
3d563f5
to
72952fe
Compare
Username: username, | ||
Password: password, | ||
} | ||
if sourceloginServer != "" { | ||
response.Auth[sourceloginServer] = v1.AuthConfig{ |
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.
mcr + acr auth is a MUST, additional auth should bring no hard.
kubelet will send mcr image + acr auth to containerd to pull mcr image, and containerd will mirror the mcr image to acr through registry host, and finally pull mcr image from acr server.
|
||
// processMirrorMapping input format: "--mirror-mapping=aaa:bbb,ccc:ddd" | ||
// output format: map[string]string{"aaa": "bbb", "ccc": "ddd"} | ||
func processMirrorMapping(mirrorMappingStr string) map[string]string { |
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.
nit, Maybe parseMirrorMapping to be specific, and to not conflict with other processXXX func.
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.
Done.
cmd/acr-credential-provider/main.go
Outdated
@@ -60,6 +63,9 @@ func main() { | |||
logs.InitLogs() | |||
defer logs.FlushLogs() | |||
|
|||
// Flags | |||
command.Flags().StringVarP(&mirrorMappingStr, "mirror-mapping", "m", "", "mirror mapping to use") |
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.
Please let's elaborate the flags. I did not see the detailed description of this flag anywhere else.
command.Flags().StringVarP(&mirrorMappingStr, "mirror-mapping", "m", "", "mirror mapping to use") | |
command.Flags().StringVarP(&mirrorMappingStr, "mirror-mapping", "m", "", "mirror mapping to mirror a source registry host to a target registry host, and image pull credentail will be requested to the target registry host when the image is from source registry host") |
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.
The name may be registry-mirror, since mirror is also the term used in containerd host namespace feature https://github.com/containerd/containerd/blob/main/docs/hosts.md#registry-host-namespace
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.
Done
72952fe
to
ec05532
Compare
With registry mirror, e.g. --registry-mirror=mcr.microsoft.com:xxx.azurecr.io credential provider will return credentials of xxx.azurecr.io for mcr.microsoft.com. In this way, an image with URL prefix mcr.microsoft.com, but actually in xxx.azurecr.io, can be successfully pulled. Signed-off-by: Zhecheng Li <zhechengli@microsoft.com>
ec05532
to
b12bb67
Compare
Verified locally. SP and MSI work. |
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.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: andyzhangx, lzhecheng The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/cherrypick release-1.31 |
/cherrypick release-1.30 |
@lzhecheng: new pull request created: #7335 In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
@lzhecheng: new pull request created: #7336 In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
What type of PR is this?
/kind feature
What this PR does / why we need it:
[credential provider] Add a flag mirrorMapping. This flag is to mirror registry A to B when fetching credential.
Which issue(s) this PR fixes:
Fixes #6845
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: