Skip to content
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

iterate on geranos MVP #155

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions cmd/geranos/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,17 @@ func Run(_ []string) error {
const sourceRegistry = "us-central1-docker.pkg.dev/k8s-artifacts-prod/images"

// TODO: make configurable later
const s3Bucket = "s3:prod-registry-k8s-io-us-east-2"
const s3Bucket = "prod-registry-k8s-io-us-east-2"

repo, err := name.NewRepository(sourceRegistry)
if err != nil {
return err
}
s3Uploader, err := newS3Uploader()
s3Uploader, err := newS3Uploader(os.Getenv("REALLY_UPLOAD") == "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
s3Uploader, err := newS3Uploader(os.Getenv("REALLY_UPLOAD") == "")
s3Uploader, err := newS3Uploader(os.Getenv("DRY_RUN") != "")

I'm new here, so maybe this makes more sense to everyone else.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default for now is to do a dry run. This would invert that default.

if err != nil {
return err
}

// for debugging: force this true
// TODO: make configurable
s3Uploader.dryRun = true

// copy layers from all images in the repo
err = WalkImageLayersGCP(repo, func(ref name.Reference, layers []v1.Layer) error {
klog.Infof("Processing image: %s", ref.String())
Expand Down
34 changes: 23 additions & 11 deletions cmd/geranos/s3uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
Expand All @@ -32,22 +33,32 @@ import (
)

// see cmd/archeio, this matches the layout of GCR's GCS bucket
const blobKeyPrefix = "/containers/images/"
// containers/images/sha256:$layer_digest
const blobKeyPrefix = "containers/images/"

type s3Uploader struct {
svc *s3.S3
uploader *s3manager.Uploader
skipExisting bool
dryRun bool
svc *s3.S3
uploader *s3manager.Uploader
reuploadLayers bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like this is used

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is read. It is not yet written.

dryRun bool
}

func newS3Uploader() (*s3Uploader, error) {
sess, err := session.NewSession()
func newS3Uploader(dryRun bool) (*s3Uploader, error) {
cfg := []*aws.Config{}
// force anonymous configs for dry run uploaders
if dryRun {
cfg = append(cfg, &aws.Config{
Credentials: credentials.AnonymousCredentials,
})
}
sess, err := session.NewSession(cfg...)
if err != nil {
return nil, err
}
r := &s3Uploader{}
r.svc = s3.New(sess)
r := &s3Uploader{
dryRun: dryRun,
svc: s3.New(sess),
}
r.uploader = s3manager.NewUploaderWithClient(r.svc)
return r, nil
}
Expand All @@ -58,11 +69,12 @@ func (s *s3Uploader) CopyToS3(bucket string, layer v1.Layer) error {
return err
}
key := keyForLayer(digest)
if s.skipExisting {
if !s.reuploadLayers {
exists, err := s.blobExists(bucket, key)
if err != nil {
klog.Errorf("failed to check if blob exists: %v", err)
} else if exists {
klog.Infof("Layer already exists: %s", key)
return nil
}
}
Expand All @@ -86,7 +98,7 @@ func (s *s3Uploader) CopyToS3(bucket string, layer v1.Layer) error {
uploadInput.ChecksumSHA256 = aws.String(base64.StdEncoding.EncodeToString(b))
}
// skip actually uploading if this is a dry-run, otherwise finally upload
klog.Infof("Uploading Layer: %s", key)
klog.Infof("Uploading layer: %s", key)
if s.dryRun {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/geranos/walkimages.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func WalkImageLayersGCP(repo name.Repository, walkImageLayers WalkImageLayersFun
// TODO: This is really just an approximation to avoid exceeding typical socket limits
// See also quota limits:
// https://cloud.google.com/artifact-registry/quotas
g.SetLimit(400)
g.SetLimit(25)
g.Go(func() error {
return google.Walk(repo, func(r name.Repository, tags *google.Tags, err error) error {
if err != nil {
Expand Down