-
Notifications
You must be signed in to change notification settings - Fork 62
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
feat: add support for "pinned" images #920
base: main
Are you sure you want to change the base?
Changes from all commits
efcc951
bdcd2e2
c30da36
7f95f58
d2d8b54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,6 +151,7 @@ replace ( | |
k8s.io/component-helpers => k8s.io/component-helpers v0.26.11 | ||
k8s.io/controller-manager => k8s.io/controller-manager v0.26.11 | ||
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.26.11 | ||
k8s.io/dynamic-resource-allocation => k8s.io/dynamic-resource-allocation v0.26.11 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hit issues locally due to the infamous
requiring me to pin this. |
||
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.26.11 | ||
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.26.11 | ||
k8s.io/kube-proxy => k8s.io/kube-proxy v0.26.11 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ var ( | |
enableProfile = flag.Bool("enable-pprof", false, "enable pprof profiling") | ||
profilePort = flag.Int("pprof-port", 6060, "port for pprof profiling. defaulted to 6060 if unspecified") | ||
scanDisabled = flag.Bool("scan-disabled", false, "boolean for if scanner container is disabled") | ||
scanPinned = flag.Bool("scan-pinned", false, "boolean for if scanner container should scan pinned images") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are making an effort to stop using cli args to control the container applications. We are using the configmap instead. In the code that spawns this pod (imagecollector_controller.go or imagejob_controller.go), we can set an environment variable based on the configmap value. For more information as to why we are moving away from cli args: |
||
|
||
// Timeout of connecting to server (default: 5m). | ||
timeout = 5 * time.Minute | ||
|
@@ -80,6 +81,11 @@ func main() { | |
} | ||
log.Info("images collected", "finalImages:", finalImages) | ||
|
||
if !(*scanPinned) { | ||
log.Info("skipping scanning pinned images") | ||
finalImages = util.RemovePinnedImages(finalImages) | ||
} | ||
|
||
data, err := json.Marshal(finalImages) | ||
if err != nil { | ||
log.Error(err, "failed to encode finalImages") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import ( | |
util "github.com/eraser-dev/eraser/pkg/utils" | ||
) | ||
|
||
func removeImages(c cri.Remover, targetImages []string) (int, error) { | ||
func removeImages(c cri.Remover, removePinned bool, targetImages []string) (int, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of passing a boolean flag, just require that the caller remove any pinned images from If the collector is turned on, filter them out during the collector stage. If the collector (and therefore scanner) is turned off, filter them out just prior to removal. |
||
removed := 0 | ||
|
||
backgroundContext, cancel := context.WithTimeout(context.Background(), timeout) | ||
|
@@ -30,6 +30,7 @@ func removeImages(c cri.Remover, targetImages []string) (int, error) { | |
newImg := unversioned.Image{ | ||
ImageID: img.Id, | ||
Names: repoTags, | ||
Pinned: img.Pinned, | ||
} | ||
|
||
digests, errs := util.ProcessRepoDigests(img.RepoDigests) | ||
|
@@ -75,6 +76,12 @@ func removeImages(c cri.Remover, targetImages []string) (int, error) { | |
continue | ||
} | ||
|
||
// TODO - figure out why is imgDigestOrTag used instead of imageID when it's called "idToImageMap" (copied usage from isExcluded). | ||
if !removePinned && util.IsPinned(imageID, idToImageMap) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason is a frustrating one: Docker's But without that feature, docker reports the sha256 digest of the Image Config as the Thus we use the digest as the hash key for the Set of images we build. Each distinct digest is a distinct image, full stop; the same is not true for ImageIDs: tag an existing image with a new name and you have one distinct image with two distinct ImageIDs. The CRI is kind of in an in-between state. It was developed to provide an interface and had to work with older clusters using dockershim and newer clusters using containerd. As such, it takes the ImageID into account more than it should. Using trivy to scan by ImageID doesn't work. Trivy scans the containerd image store by creating a containerd client (from the containerd library) and querying it directly. Since containerd doesn't manage images by docker's ImageID, it can't provide any image information to trivy for the scan if it's looking for it by ImageID. We want to scan and remove by content as much as possible, not by name. We use the image name + tag as a backup in the event that the call to the CRI's |
||
log.Info("image is kept due to being pinned", "given", imgDigestOrTag, "imageID", imageID, "name", idToImageMap[imageID]) | ||
continue | ||
} | ||
|
||
err = c.DeleteImage(backgroundContext, imageID) | ||
if err != nil { | ||
log.Error(err, "error removing image", "given", imgDigestOrTag, "imageID", imageID, "name", idToImageMap[imageID]) | ||
|
@@ -108,6 +115,11 @@ func removeImages(c cri.Remover, targetImages []string) (int, error) { | |
continue | ||
} | ||
|
||
if !removePinned && util.IsPinned(imageID, idToImageMap) { | ||
log.Info("image is kept due to being pinned", "imageID", imageID, "name", idToImageMap[imageID]) | ||
continue | ||
} | ||
|
||
if err := c.DeleteImage(backgroundContext, imageID); err != nil { | ||
success = false | ||
log.Error(err, "error removing image", "imageID", imageID, "name", idToImageMap[imageID]) | ||
|
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 want to make a simultaneous identical change to
v1
andunversioned
. We keepunversioned
synchronized with the latest api version for each type. Currently: