mirror of
https://github.com/lukaszraczylo/kubernetes-images-sync-operator.git
synced 2026-06-10 23:29:11 +00:00
Add ability to include/exclude namespaces.
This commit is contained in:
@@ -5,10 +5,9 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
// JOB IMAGES
|
||||
BACKUP_JOB_IMAGE = "ghcr.io/lukaszraczylo/kubernetes-images-sync-worker:1.0.2"
|
||||
var BACKUP_JOB_IMAGE = "ghcr.io/lukaszraczylo/kubernetes-images-sync-worker:1.0.2"
|
||||
|
||||
const (
|
||||
// AVAILABLE STATUSES
|
||||
STATUS_PENDING = "PENDING"
|
||||
STATUS_STARTING = "STARTING"
|
||||
@@ -24,10 +23,11 @@ const (
|
||||
)
|
||||
|
||||
type Container struct {
|
||||
Image string `json:"image"`
|
||||
Tag string `json:"tag"`
|
||||
Sha string `json:"sha"`
|
||||
FullName string `json:"fullName"`
|
||||
Image string `json:"image"`
|
||||
Tag string `json:"tag"`
|
||||
Sha string `json:"sha"`
|
||||
FullName string `json:"fullName"`
|
||||
ImageNamespace string `json:"imageNamespace"`
|
||||
}
|
||||
|
||||
type ContainersList struct {
|
||||
@@ -96,3 +96,34 @@ func NormalizeImageName(name string) string {
|
||||
// Trim leading and trailing hyphens
|
||||
return strings.Trim(normalized, "-")
|
||||
}
|
||||
|
||||
// filterOnlyFromNamespaces filters out containers from namespaces that are not in the list
|
||||
func FilterOnlyFromNamespaces(containers ContainersList, namespaces []string) ContainersList {
|
||||
result := ContainersList{}
|
||||
for _, container := range containers.Containers {
|
||||
for _, namespace := range namespaces {
|
||||
if container.ImageNamespace == namespace {
|
||||
result.Containers = append(result.Containers, container)
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// filterOutWholeNamespaces filters out containers from namespaces that are in the list
|
||||
func FilterOutWholeNamespaces(containers ContainersList, namespaces []string) ContainersList {
|
||||
result := ContainersList{}
|
||||
for _, container := range containers.Containers {
|
||||
excluded := false
|
||||
for _, namespace := range namespaces {
|
||||
if container.ImageNamespace == namespace {
|
||||
excluded = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !excluded {
|
||||
result.Containers = append(result.Containers, container)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user