Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
  • Loading branch information
fabriziosestito committed Nov 7, 2024
1 parent 0ae0c36 commit b049bd7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
4 changes: 3 additions & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ local_resource(
"cmd/controller",
"api",
"internal/controller",
],
],
)

entrypoint = ["/controller"]
Expand Down Expand Up @@ -102,6 +102,8 @@ local_resource(
"go.sum",
"cmd/worker",
"api",
"internal/messaging",
"internal/handlers",
],
)

Expand Down
14 changes: 7 additions & 7 deletions cmd/worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ import (
)

func main() {
logger, err := zap.NewProduction()
logger, err := zap.NewDevelopment()
if err != nil {
panic(fmt.Sprintf("failed to create logger: %v", err))
}
defer logger.Sync() //nolint: errcheck // flushes buffer, ignore error

logger.Info("Starting worker")

sub, err := messaging.NewSubscription("nats://controller-nats.sbombastic.svc.cluster.local",
"worker")
if err != nil {
Expand Down Expand Up @@ -65,10 +67,8 @@ func main() {
cancel()
}()

go func() {
err := subscriber.Run(ctx)
if err != nil {
logger.Fatal("Error running worker subscriber", zap.Error(err))
}
}()
err = subscriber.Run(ctx)
if err != nil {
logger.Fatal("Error running worker subscriber", zap.Error(err))
}
}
2 changes: 1 addition & 1 deletion helm/templates/worker/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec:
labels:
worker: "true"
spec:
serviceAccountName: apiserver
serviceAccountName: controller-manager
containers:
- name: wardle-server
image: {{ .Values.worker.image.repository }}:{{ .Values.worker.image.tag }}
Expand Down
15 changes: 8 additions & 7 deletions internal/handlers/create_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (h *CreateCatalogHandler) Handle(message messaging.Message) error {
continue
}

images, err := h.refToImages(registryClient, ref)
images, err := h.refToImages(registryClient, ref, registry.Namespace)
if err != nil {
h.logger.Error(
"cannot convert reference to Image",
Expand Down Expand Up @@ -167,7 +167,7 @@ func (h *CreateCatalogHandler) discoverImages(ctx context.Context, registryClien
return contents, nil
}

func (h *CreateCatalogHandler) refToImages(registryClient registryclient.Client, ref name.Reference) ([]v1alpha1.Image, error) {
func (h *CreateCatalogHandler) refToImages(registryClient registryclient.Client, ref name.Reference, namespace string) ([]v1alpha1.Image, error) {
platforms, err := h.refToPlatforms(registryClient, ref)
if err != nil {
return []v1alpha1.Image{}, fmt.Errorf("cannot get platforms for %s: %w", ref, err)
Expand Down Expand Up @@ -200,6 +200,7 @@ func (h *CreateCatalogHandler) refToImages(registryClient registryclient.Client,
h.logger.Error("cannot convert image details to image", zap.Error(err))
continue
}
image.SetNamespace(namespace)

images = append(images, image)
}
Expand Down Expand Up @@ -294,11 +295,11 @@ func imageDetailsToImage(ref name.Reference, details registryclient.ImageDetails
ObjectMeta: metav1.ObjectMeta{
Name: computeImageUID(ref, details.Digest.String()),
Labels: map[string]string{
v1alpha1.ImageRegistryLabel: ref.Context().RegistryStr(),
v1alpha1.ImageRepositoryLabel: ref.Context().RepositoryStr(),
v1alpha1.ImageTagLabel: ref.Identifier(),
v1alpha1.ImagePlatformLabel: details.Platform.String(),
v1alpha1.ImageDigestLabel: details.Digest.String(),
v1alpha1.ImageRegistryLabel: ref.Context().RegistryStr(),
// v1alpha1.ImageRepositoryLabel: ref.Context().RepositoryStr(),
v1alpha1.ImageTagLabel: ref.Identifier(),
// v1alpha1.ImagePlatformLabel: details.Platform.String(),
// v1alpha1.ImageDigestLabel: details.Digest.String(),
},
},
Spec: v1alpha1.ImageSpec{
Expand Down
2 changes: 2 additions & 0 deletions internal/handlers/create_catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,15 @@ func TestCreateCatalogHandler_Handle(t *testing.T) {
assert.Equal(t, imageList.Items[0].Labels[v1alpha1.ImageTagLabel], imageTag)
assert.Equal(t, imageList.Items[0].Labels[v1alpha1.ImagePlatformLabel], platformLinuxAmd64.String())
assert.Equal(t, imageList.Items[0].Labels[v1alpha1.ImageDigestLabel], digestLinuxAmd64.String())
assert.Equal(t, imageList.Items[0].Namespace, registry.Namespace)
assert.Len(t, imageList.Items[0].Spec.Layers, 8)

assert.Equal(t, imageList.Items[1].Labels[v1alpha1.ImageRegistryLabel], registryURL)
assert.Equal(t, imageList.Items[1].Labels[v1alpha1.ImageRepositoryLabel], repositoryName)
assert.Equal(t, imageList.Items[1].Labels[v1alpha1.ImageTagLabel], imageTag)
assert.Equal(t, imageList.Items[1].Labels[v1alpha1.ImagePlatformLabel], platformLinuxArm64.String())
assert.Equal(t, imageList.Items[1].Labels[v1alpha1.ImageDigestLabel], digestLinuxArm64.String())
assert.Equal(t, imageList.Items[1].Namespace, registry.Namespace)
assert.Len(t, imageList.Items[0].Spec.Layers, 8)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/handlers/registry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (c *client) Catalog(ctx context.Context, registry name.Registry) ([]string,

catalogger, err := puller.Catalogger(ctx, registry)
if err != nil {
return []string{}, fmt.Errorf("cannot create catologger for %s: %w", registry.Name(), err)
return []string{}, fmt.Errorf("cannot create catalogger for %s: %w", registry.Name(), err)
}

repositories := []string{}
Expand Down

0 comments on commit b049bd7

Please sign in to comment.