Skip to content

Commit

Permalink
Add ability to support registryOverride
Browse files Browse the repository at this point in the history
  • Loading branch information
Daishan committed Apr 6, 2021
1 parent 3769345 commit 2309fbb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/podimpersonation/podimpersonation.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ type PodOptions struct {
ConfigMapsToCreate []*v1.ConfigMap
SecretsToCreate []*v1.Secret
Wait bool
ImageOverride string
}

// CreatePod will create a pod with a service account that impersonates as user. Corresponding
Expand Down Expand Up @@ -338,7 +339,7 @@ func (s *PodImpersonation) createPod(ctx context.Context, user user.Info, role *
return nil, err
}

pod = s.augmentPod(pod, sa)
pod = s.augmentPod(pod, sa, podOptions.ImageOverride)

if err := s.createConfigMaps(ctx, user, role, pod, podOptions, client); err != nil {
return nil, err
Expand Down Expand Up @@ -488,7 +489,7 @@ func (s *PodImpersonation) adminKubeConfig(user user.Info, role *rbacv1.ClusterR
}, nil
}

func (s *PodImpersonation) augmentPod(pod *v1.Pod, sa *v1.ServiceAccount) *v1.Pod {
func (s *PodImpersonation) augmentPod(pod *v1.Pod, sa *v1.ServiceAccount, imageOverride string) *v1.Pod {
var (
zero = int64(0)
t = true
Expand Down Expand Up @@ -547,9 +548,14 @@ func (s *PodImpersonation) augmentPod(pod *v1.Pod, sa *v1.ServiceAccount) *v1.Po
}
}

image := imageOverride
if image == "" {
image = s.imageName()
}

pod.Spec.Containers = append(pod.Spec.Containers, v1.Container{
Name: "proxy",
Image: s.imageName(),
Image: image,
ImagePullPolicy: v1.PullIfNotPresent,
Env: []v1.EnvVar{
{
Expand Down
3 changes: 3 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Server struct {
BaseSchemas *types.APISchemas
AccessSetLookup accesscontrol.AccessSetLookup
APIServer *apiserver.Server
ClusterRegistry string

authMiddleware auth.Middleware
controllers *Controllers
Expand All @@ -57,6 +58,7 @@ type Options struct {
Router router.RouterFunc
AggregationSecretNamespace string
AggregationSecretName string
ClusterRegistry string
}

func New(ctx context.Context, restConfig *rest.Config, opts *Options) (*Server, error) {
Expand All @@ -74,6 +76,7 @@ func New(ctx context.Context, restConfig *rest.Config, opts *Options) (*Server,
router: opts.Router,
aggregationSecretNamespace: opts.AggregationSecretNamespace,
aggregationSecretName: opts.AggregationSecretName,
ClusterRegistry: opts.ClusterRegistry,
}

if err := setup(ctx, server); err != nil {
Expand Down

0 comments on commit 2309fbb

Please sign in to comment.