@@ -925,6 +925,10 @@ func containerToV1Container(ctx context.Context, c *Container, getService bool)
925925 return kubeContainer , kubeVolumes , nil , annotations , fmt .Errorf ("linux devices: %w" , define .ErrNotImplemented )
926926 }
927927
928+ if ! c .IsInfra () && len (c .config .Rootfs ) > 0 {
929+ return kubeContainer , kubeVolumes , nil , annotations , fmt .Errorf ("k8s does not support Rootfs" )
930+ }
931+
928932 if len (c .config .UserVolumes ) > 0 {
929933 volumeMounts , volumes , localAnnotations , err := libpodMountsToKubeVolumeMounts (c )
930934 if err != nil {
@@ -957,53 +961,44 @@ func containerToV1Container(ctx context.Context, c *Container, getService bool)
957961 kubeContainer .Name = removeUnderscores (c .Name ())
958962 _ , image := c .Image ()
959963
960- // The infra container may have been created with an overlay root FS
961- // instead of an infra image. If so, set the imageto the default K8s
962- // pause one and make sure it's in the storage by pulling it down if
963- // missing.
964- if image == "" && c .IsInfra () {
965- image = c .runtime .config .Engine .InfraImage
966- if _ , err := c .runtime .libimageRuntime .Pull (ctx , image , config .PullPolicyMissing , nil ); err != nil {
967- return kubeContainer , nil , nil , nil , err
968- }
969- }
970-
971964 kubeContainer .Image = image
972965 kubeContainer .Stdin = c .Stdin ()
973- img , _ , err := c .runtime .libimageRuntime .LookupImage (image , nil )
974- if err != nil {
975- return kubeContainer , kubeVolumes , nil , annotations , fmt .Errorf ("looking up image %q of container %q: %w" , image , c .ID (), err )
976- }
977- imgData , err := img .Inspect (ctx , nil )
978- if err != nil {
979- return kubeContainer , kubeVolumes , nil , annotations , err
980- }
981- // If the user doesn't set a command/entrypoint when creating the container with podman and
982- // is using the image command or entrypoint from the image, don't add it to the generated kube yaml
983- if reflect .DeepEqual (imgData .Config .Cmd , kubeContainer .Command ) || reflect .DeepEqual (imgData .Config .Entrypoint , kubeContainer .Command ) {
984- kubeContainer .Command = nil
985- }
966+ if len (image ) > 0 {
967+ img , _ , err := c .runtime .libimageRuntime .LookupImage (image , nil )
968+ if err != nil {
969+ return kubeContainer , kubeVolumes , nil , annotations , fmt .Errorf ("looking up image %q of container %q: %w" , image , c .ID (), err )
970+ }
971+ imgData , err := img .Inspect (ctx , nil )
972+ if err != nil {
973+ return kubeContainer , kubeVolumes , nil , annotations , err
974+ }
975+ // If the user doesn't set a command/entrypoint when creating the container with podman and
976+ // is using the image command or entrypoint from the image, don't add it to the generated kube yaml
977+ if reflect .DeepEqual (imgData .Config .Cmd , kubeContainer .Command ) || reflect .DeepEqual (imgData .Config .Entrypoint , kubeContainer .Command ) {
978+ kubeContainer .Command = nil
979+ }
986980
987- if c .WorkingDir () != "/" && imgData .Config .WorkingDir != c .WorkingDir () {
988- kubeContainer .WorkingDir = c .WorkingDir ()
989- }
981+ if c .WorkingDir () != "/" && imgData .Config .WorkingDir != c .WorkingDir () {
982+ kubeContainer .WorkingDir = c .WorkingDir ()
983+ }
990984
991- if imgData .User == c .User () && hasSecData {
992- kubeSec .RunAsGroup , kubeSec .RunAsUser = nil , nil
993- }
994- // If the image has user set as a positive integer value, then set runAsNonRoot to true
995- // in the kube yaml
996- imgUserID , err := strconv .Atoi (imgData .User )
997- if err == nil && imgUserID > 0 {
998- trueBool := true
999- kubeSec .RunAsNonRoot = & trueBool
1000- }
985+ if imgData .User == c .User () && hasSecData {
986+ kubeSec .RunAsGroup , kubeSec .RunAsUser = nil , nil
987+ }
988+ // If the image has user set as a positive integer value, then set runAsNonRoot to true
989+ // in the kube yaml
990+ imgUserID , err := strconv .Atoi (imgData .User )
991+ if err == nil && imgUserID > 0 {
992+ trueBool := true
993+ kubeSec .RunAsNonRoot = & trueBool
994+ }
1001995
1002- envVariables , err := libpodEnvVarsToKubeEnvVars (c .config .Spec .Process .Env , imgData .Config .Env )
1003- if err != nil {
1004- return kubeContainer , kubeVolumes , nil , annotations , err
996+ envVariables , err := libpodEnvVarsToKubeEnvVars (c .config .Spec .Process .Env , imgData .Config .Env )
997+ if err != nil {
998+ return kubeContainer , kubeVolumes , nil , annotations , err
999+ }
1000+ kubeContainer .Env = envVariables
10051001 }
1006- kubeContainer .Env = envVariables
10071002
10081003 kubeContainer .Ports = ports
10091004 // This should not be applicable
0 commit comments