Skip to content

Commit

Permalink
Merge branch 'cs_gpu' of github.com:google/go-tpm-tools into version_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
meetrajvala committed Dec 24, 2024
2 parents 4c7d153 + b9cc2ba commit b9bb78a
Showing 1 changed file with 5 additions and 37 deletions.
42 changes: 5 additions & 37 deletions launcher/container_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func NewRunner(ctx context.Context, cdClient *containerd.Client, token oauth2.To
return nil, err
}

logger.Info(fmt.Sprintf("Launch Policy : %+v\n", launchPolicy))
logger.Info("Launch Policy : %+v\n", launchPolicy)

if imageConfigDescriptor, err := image.Config(ctx); err != nil {
logger.Error(err.Error())
Expand Down Expand Up @@ -295,12 +295,7 @@ func getSignatureDiscoveryClient(cdClient *containerd.Client, mdsClient *metadat
return registryauth.RefreshResolver(ctx, mdsClient)
}
imageFetcher := func(ctx context.Context, imageRef string, opts ...containerd.RemoteOpt) (containerd.Image, error) {
image, err := pullImageWithRetries(
func() (containerd.Image, error) {
return cdClient.Pull(ctx, imageRef, opts...)
},
pullImageBackoffPolicy,
)
image, err := cdClient.Pull(ctx, imageRef, opts...)
if err != nil {
return nil, fmt.Errorf("cannot pull signature objects from the signature image [%s]: %w", imageRef, err)
}
Expand Down Expand Up @@ -562,11 +557,6 @@ func defaultRetryPolicy() *backoff.ExponentialBackOff {
return expBack
}

func pullImageBackoffPolicy() backoff.BackOff {
b := backoff.NewConstantBackOff(time.Millisecond * 500)
return backoff.WithMaxRetries(b, 3)
}

// Run the container
// Container output will always be redirected to logger writer for now
func (r *ContainerRunner) Run(ctx context.Context) error {
Expand Down Expand Up @@ -659,39 +649,17 @@ func (r *ContainerRunner) Run(ctx context.Context) error {
return nil
}

func pullImageWithRetries(f func() (containerd.Image, error), retry func() backoff.BackOff) (containerd.Image, error) {
var err error
var image containerd.Image
err = backoff.Retry(func() error {
image, err = f()
return err
}, retry())
if err != nil {
return nil, fmt.Errorf("failed to pull image with retries, the last error is: %w", err)
}
return image, nil
}

func initImage(ctx context.Context, cdClient *containerd.Client, launchSpec spec.LaunchSpec, token oauth2.Token) (containerd.Image, error) {
if token.Valid() {
remoteOpt := containerd.WithResolver(registryauth.Resolver(token.AccessToken))
image, err := pullImageWithRetries(
func() (containerd.Image, error) {
return cdClient.Pull(ctx, launchSpec.ImageRef, containerd.WithPullUnpack, remoteOpt)
},
pullImageBackoffPolicy,
)

image, err := cdClient.Pull(ctx, launchSpec.ImageRef, containerd.WithPullUnpack, remoteOpt)
if err != nil {
return nil, fmt.Errorf("cannot pull the image: %w", err)
}
return image, nil
}
image, err := pullImageWithRetries(
func() (containerd.Image, error) {
return cdClient.Pull(ctx, launchSpec.ImageRef, containerd.WithPullUnpack)
},
pullImageBackoffPolicy,
)
image, err := cdClient.Pull(ctx, launchSpec.ImageRef, containerd.WithPullUnpack)
if err != nil {
return nil, fmt.Errorf("cannot pull the image (no token, only works for a public image): %w", err)
}
Expand Down

0 comments on commit b9bb78a

Please sign in to comment.