diff --git a/cmd/installer/main.go b/cmd/installer/main.go index a9270f9..2b27520 100644 --- a/cmd/installer/main.go +++ b/cmd/installer/main.go @@ -72,7 +72,9 @@ network-lock skip "zeropod.ctrox.dev/scaledown-duration", "zeropod.ctrox.dev/disable-checkpointing", "zeropod.ctrox.dev/pre-dump", - "io.containerd.runc.v2.group" + "io.containerd.runc.v2.group", + "vcluster.loft.sh/name", + "vcluster.loft.sh/namespace" ] ` ) diff --git a/zeropod/config.go b/zeropod/config.go index 9ed315b..0360aae 100644 --- a/zeropod/config.go +++ b/zeropod/config.go @@ -23,6 +23,8 @@ const ( PreDumpAnnotationKey = "zeropod.ctrox.dev/pre-dump" CRIContainerNameAnnotation = "io.kubernetes.cri.container-name" CRIContainerTypeAnnotation = "io.kubernetes.cri.container-type" + VClusterNameAnnotationKey = "vcluster.loft.sh/name" + VClusterNamespaceAnnotationKey = "vcluster.loft.sh/namespace" defaultScaleDownDuration = time.Minute containersDelim = "," @@ -43,6 +45,8 @@ type annotationConfig struct { PodName string `mapstructure:"io.kubernetes.cri.sandbox-name"` PodNamespace string `mapstructure:"io.kubernetes.cri.sandbox-namespace"` PodUID string `mapstructure:"io.kubernetes.cri.sandbox-uid"` + VClusterPodName string `mapstructure:"vcluster.loft.sh/name"` + VClusterPodNamespace string `mapstructure:"vcluster.loft.sh/namespace"` } type Config struct { @@ -53,11 +57,13 @@ type Config struct { PreDump bool ContainerName string ContainerType string - PodName string - PodNamespace string - PodUID string + podName string + podNamespace string + podUID string ContainerdNamespace string spec *specs.Spec + vclusterPodName string + vclusterPodNamespace string } // NewConfig uses the annotations from the container spec to create a new @@ -141,11 +147,13 @@ func NewConfig(ctx context.Context, spec *specs.Spec) (*Config, error) { ZeropodContainerNames: containerNames, ContainerName: cfg.ContainerName, ContainerType: cfg.ContainerType, - PodName: cfg.PodName, - PodNamespace: cfg.PodNamespace, - PodUID: cfg.PodUID, ContainerdNamespace: ns, + podName: cfg.PodName, + podNamespace: cfg.PodNamespace, + podUID: cfg.PodUID, spec: spec, + vclusterPodName: cfg.VClusterPodName, + vclusterPodNamespace: cfg.VClusterPodNamespace, }, nil } @@ -159,3 +167,29 @@ func (cfg Config) IsZeropodContainer() bool { // if there is none specified, every one of them is considered. return len(cfg.ZeropodContainerNames) == 0 } + +func (cfg Config) HostPodName() string { + return cfg.podName +} + +func (cfg Config) HostPodNamespace() string { + return cfg.podNamespace +} + +func (cfg Config) HostPodUID() string { + return cfg.podUID +} + +func (cfg Config) PodName() string { + if cfg.vclusterPodName != "" { + return cfg.vclusterPodName + } + return cfg.podName +} + +func (cfg Config) PodNamespace() string { + if cfg.vclusterPodNamespace != "" { + return cfg.vclusterPodNamespace + } + return cfg.podNamespace +} diff --git a/zeropod/container.go b/zeropod/container.go index 93ef148..3c0ce2f 100644 --- a/zeropod/container.go +++ b/zeropod/container.go @@ -64,7 +64,7 @@ func New(ctx context.Context, cfg *Config, cr *sync.Mutex, container *runc.Conta return nil, err } - logPath, err := getLogPath(ctx, cfg) + logPath, err := getLogPath(cfg) if err != nil { return nil, fmt.Errorf("unable to get log path: %w", err) } @@ -174,8 +174,8 @@ func (c *Container) Status() *v1.ContainerStatus { return &v1.ContainerStatus{ Id: c.ID(), Name: c.cfg.ContainerName, - PodName: c.cfg.PodName, - PodNamespace: c.cfg.PodNamespace, + PodName: c.cfg.PodName(), + PodNamespace: c.cfg.PodNamespace(), Phase: phase, } } diff --git a/zeropod/log.go b/zeropod/log.go index 4b36e55..6ab12a8 100644 --- a/zeropod/log.go +++ b/zeropod/log.go @@ -1,7 +1,6 @@ package zeropod import ( - "context" "fmt" "os" "path/filepath" @@ -14,8 +13,8 @@ import ( // containerd only passes that to the sandbox container (pause). One possible // solution would be to implement log restoring in the sandbox container // instead of the zeropod. -func getLogPath(ctx context.Context, cfg *Config) (string, error) { - logDir := fmt.Sprintf("/var/log/pods/%s_%s_%s/%s", cfg.PodNamespace, cfg.PodName, cfg.PodUID, cfg.ContainerName) +func getLogPath(cfg *Config) (string, error) { + logDir := fmt.Sprintf("/var/log/pods/%s_%s_%s/%s", cfg.HostPodNamespace(), cfg.HostPodName(), cfg.HostPodUID(), cfg.ContainerName) dir, err := os.Open(logDir) if err != nil { diff --git a/zeropod/metrics.go b/zeropod/metrics.go index 6a708d4..654ee9c 100644 --- a/zeropod/metrics.go +++ b/zeropod/metrics.go @@ -74,8 +74,8 @@ func NewRegistry() *prometheus.Registry { func (c *Container) labels() map[string]string { return map[string]string{ labelContainerName: c.cfg.ContainerName, - LabelPodName: c.cfg.PodName, - LabelPodNamespace: c.cfg.PodNamespace, + LabelPodName: c.cfg.PodName(), + LabelPodNamespace: c.cfg.PodNamespace(), } }