Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
frewilhelm committed Feb 6, 2025
1 parent 6581673 commit 9568d38
Show file tree
Hide file tree
Showing 17 changed files with 348 additions and 252 deletions.
4 changes: 2 additions & 2 deletions api/v1alpha1/configuredresource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ type ConfiguredResourceStatus struct {

// The configuration reconcile loop generates an artifact, which contains the
// ConfiguredResourceSpec.Target ConfigurationReference after configuration.
// It is filled once the Artifact is created and the configuration completed.
ArtifactRef *ObjectKey `json:"artifactRef,omitempty"`
// It is filled once the Snapshot is created and the configuration completed.
SnapshotRef *ObjectKey `json:"snapshotRef,omitempty"`

// Digest contains a technical identifier for the artifact. This technical identifier
// can be used to track changes on the ArtifactRef as it is a combination of the origin
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/localizedresource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ type LocalizedResourceStatus struct {
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty"`

// The LocalizedResource reports an ArtifactRef which contains the content of the Resource after Localization
ArtifactRef *ObjectKey `json:"artifactRef,omitempty"`
// The LocalizedResource reports an SnapshotRef which contains the content of the Resource after Localization
SnapshotRef *ObjectKey `json:"snapshotRef,omitempty"`

// The LocalizedResource reports a ConfiguredResourceRef which contains a reference to the ConfiguredResource
// that is responsible for generating the ArtifactRef.
Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ func main() {
EventRecorder: eventsRecorder,
},
Registry: registry,
Storage: storage,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Resource")
os.Exit(1)
Expand All @@ -224,8 +223,8 @@ func main() {
Scheme: mgr.GetScheme(),
EventRecorder: eventsRecorder,
},
Storage: storage,
LocalizationClient: locclient.NewClientWithLocalStorage(mgr.GetClient(), storage, mgr.GetScheme()),
Registry: registry,
LocalizationClient: locclient.NewClientWithRegistry(mgr.GetClient(), registry, mgr.GetScheme()),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "LocalizedResource")
os.Exit(1)
Expand Down
26 changes: 13 additions & 13 deletions config/crd/bases/delivery.ocm.software_configuredresources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,6 @@ spec:
status:
description: ConfiguredResourceStatus defines the observed state of ConfiguredResource.
properties:
artifactRef:
description: |-
The configuration reconcile loop generates an artifact, which contains the
ConfiguredResourceSpec.Target ConfigurationReference after configuration.
It is filled once the Artifact is created and the configuration completed.
properties:
name:
type: string
namespace:
type: string
required:
- name
type: object
conditions:
items:
description: Condition contains details for one aspect of the current
Expand Down Expand Up @@ -177,6 +164,19 @@ spec:
observedGeneration:
format: int64
type: integer
snapshotRef:
description: |-
The configuration reconcile loop generates an artifact, which contains the
ConfiguredResourceSpec.Target ConfigurationReference after configuration.
It is filled once the Snapshot is created and the configuration completed.
properties:
name:
type: string
namespace:
type: string
required:
- name
type: object
type: object
type: object
served: true
Expand Down
22 changes: 11 additions & 11 deletions config/crd/bases/delivery.ocm.software_localizedresources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,6 @@ spec:
type: object
status:
properties:
artifactRef:
description: The LocalizedResource reports an ArtifactRef which contains
the content of the Resource after Localization
properties:
name:
type: string
namespace:
type: string
required:
- name
type: object
conditions:
items:
description: Condition contains details for one aspect of the current
Expand Down Expand Up @@ -196,6 +185,17 @@ spec:
observedGeneration:
format: int64
type: integer
snapshotRef:
description: The LocalizedResource reports an SnapshotRef which contains
the content of the Resource after Localization
properties:
name:
type: string
namespace:
type: string
required:
- name
type: object
type: object
type: object
served: true
Expand Down
26 changes: 13 additions & 13 deletions internal/controller/configuration/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"context"
"fmt"

"github.com/openfluxcd/controller-manager/storage"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/open-component-model/ocm-k8s-toolkit/api/v1alpha1"
"github.com/open-component-model/ocm-k8s-toolkit/internal/controller/configuration/types"
artifactutil "github.com/open-component-model/ocm-k8s-toolkit/pkg/artifact"
snapshotRegistry "github.com/open-component-model/ocm-k8s-toolkit/pkg/snapshot"
)

type Client interface {
Expand All @@ -24,24 +24,24 @@ type Client interface {
GetTarget(ctx context.Context, ref v1alpha1.ConfigurationReference) (target types.ConfigurationTarget, err error)
}

func NewClientWithLocalStorage(r client.Reader, s *storage.Storage, scheme *runtime.Scheme) Client {
func NewClientWithLocalStorage(c client.Client, r snapshotRegistry.RegistryType, scheme *runtime.Scheme) Client {
factory := serializer.NewCodecFactory(scheme)
info, _ := runtime.SerializerInfoForMediaType(factory.SupportedMediaTypes(), runtime.ContentTypeYAML)
encoder := factory.EncoderForVersion(info.Serializer, v1alpha1.GroupVersion)

return &localStorageBackedClient{
Reader: r,
Storage: s,
scheme: scheme,
encoder: encoder,
Client: c,
Registry: r,
scheme: scheme,
encoder: encoder,
}
}

type localStorageBackedClient struct {
client.Reader
*storage.Storage
scheme *runtime.Scheme
encoder runtime.Encoder
client.Client
Registry snapshotRegistry.RegistryType
scheme *runtime.Scheme
encoder runtime.Encoder
}

var _ Client = &localStorageBackedClient{}
Expand All @@ -57,7 +57,7 @@ func (clnt *localStorageBackedClient) GetTarget(ctx context.Context, ref v1alpha
case v1alpha1.KindLocalizedResource:
fallthrough
case v1alpha1.KindResource:
return artifactutil.GetContentBackedByArtifactFromComponent(ctx, clnt.Reader, clnt.Storage, &ref)
return artifactutil.GetContentBackedBySnapshotFromComponent(ctx, clnt.Client, clnt.Registry, &ref)
default:
return nil, fmt.Errorf("unsupported configuration target kind: %s", ref.Kind)
}
Expand All @@ -66,9 +66,9 @@ func (clnt *localStorageBackedClient) GetTarget(ctx context.Context, ref v1alpha
func (clnt *localStorageBackedClient) GetConfiguration(ctx context.Context, ref v1alpha1.ConfigurationReference) (source types.ConfigurationSource, err error) {
switch ref.Kind {
case v1alpha1.KindResource:
return artifactutil.GetContentBackedByArtifactFromComponent(ctx, clnt.Reader, clnt.Storage, &ref)
return artifactutil.GetContentBackedBySnapshotFromComponent(ctx, clnt.Client, clnt.Registry, &ref)
case v1alpha1.KindResourceConfig:
return GetResourceConfigFromKubernetes(ctx, clnt.Reader, clnt.encoder, ref)
return GetResourceConfigFromKubernetes(ctx, clnt.Client, clnt.encoder, ref)
default:
return nil, fmt.Errorf("unsupported configuration source kind: %s", ref.Kind)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/open-component-model/ocm-k8s-toolkit/pkg/artifact"
"github.com/open-component-model/ocm-k8s-toolkit/pkg/index"
"github.com/open-component-model/ocm-k8s-toolkit/pkg/ocm"
snapshotRegistry "github.com/open-component-model/ocm-k8s-toolkit/pkg/snapshot"
"github.com/open-component-model/ocm-k8s-toolkit/pkg/status"
)

Expand Down Expand Up @@ -71,6 +72,7 @@ type Reconciler struct {
*ocm.BaseReconciler
*storage.Storage
ConfigClient configurationclient.Client
Registry snapshotRegistry.RegistryType
}

// +kubebuilder:rbac:groups=delivery.ocm.software,resources=configuredresources,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -160,7 +162,7 @@ func (r *Reconciler) reconcileExists(ctx context.Context, configuration *v1alpha
return ctrl.Result{}, fmt.Errorf("failed to fetch cfg: %w", err)
}

digest, revision, filename, err := artifact.UniqueIDsForArtifactContentCombination(cfg, target)
digest, revision, filename, err := artifact.UniqueIDsForSnapshotContentCombination(cfg, target)
if err != nil {
status.MarkNotReady(r.EventRecorder, configuration, v1alpha1.UniqueIDGenerationFailedReason, err.Error())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var _ = Describe("ConfiguredResource Controller", func() {
fileContentAfterConfiguration := []byte(`mykey: "substituted"`)

dir := filepath.Join(tmp, "test")
test.CreateTGZ(dir, map[string][]byte{
test.CreateTGZFromData(dir, map[string][]byte{
fileToConfigure: fileContentBeforeConfiguration,
})

Expand Down
26 changes: 13 additions & 13 deletions internal/controller/localization/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"context"
"fmt"

"github.com/openfluxcd/controller-manager/storage"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/open-component-model/ocm-k8s-toolkit/api/v1alpha1"
"github.com/open-component-model/ocm-k8s-toolkit/internal/controller/localization/types"
artifactutil "github.com/open-component-model/ocm-k8s-toolkit/pkg/artifact"
"github.com/open-component-model/ocm-k8s-toolkit/pkg/snapshot"
)

type Client interface {
Expand All @@ -27,24 +27,24 @@ type Client interface {
GetLocalizationConfig(ctx context.Context, ref v1alpha1.ConfigurationReference) (source types.LocalizationConfig, err error)
}

func NewClientWithLocalStorage(r client.Reader, s *storage.Storage, scheme *runtime.Scheme) Client {
func NewClientWithRegistry(c client.Client, registry *snapshot.Registry, scheme *runtime.Scheme) Client {
factory := serializer.NewCodecFactory(scheme)
info, _ := runtime.SerializerInfoForMediaType(factory.SupportedMediaTypes(), runtime.ContentTypeYAML)
encoder := factory.EncoderForVersion(info.Serializer, v1alpha1.GroupVersion)

return &localStorageBackedClient{
Reader: r,
Storage: s,
scheme: scheme,
encoder: encoder,
Client: c,
Registry: registry,
scheme: scheme,
encoder: encoder,
}
}

type localStorageBackedClient struct {
client.Reader
*storage.Storage
scheme *runtime.Scheme
encoder runtime.Encoder
client.Client
Registry *snapshot.Registry
scheme *runtime.Scheme
encoder runtime.Encoder
}

func (clnt *localStorageBackedClient) Scheme() *runtime.Scheme {
Expand All @@ -63,7 +63,7 @@ func (clnt *localStorageBackedClient) GetLocalizationTarget(
case v1alpha1.KindLocalizedResource:
fallthrough
case v1alpha1.KindResource:
return artifactutil.GetContentBackedByArtifactFromComponent(ctx, clnt.Reader, clnt.Storage, &ref)
return artifactutil.GetContentBackedBySnapshotFromComponent(ctx, clnt.Client, clnt.Registry, &ref)
default:
return nil, fmt.Errorf("unsupported localization target kind: %s", ref.Kind)
}
Expand All @@ -75,9 +75,9 @@ func (clnt *localStorageBackedClient) GetLocalizationConfig(
) (types.LocalizationConfig, error) {
switch ref.Kind {
case v1alpha1.KindResource:
return artifactutil.GetContentBackedByArtifactFromComponent(ctx, clnt.Reader, clnt.Storage, &ref)
return artifactutil.GetContentBackedBySnapshotFromComponent(ctx, clnt.Client, clnt.Registry, &ref)
case v1alpha1.KindLocalizationConfig:
return GetLocalizationConfigFromKubernetes(ctx, clnt.Reader, clnt.encoder, ref)
return GetLocalizationConfigFromKubernetes(ctx, clnt.Client, clnt.encoder, ref)
default:
return nil, fmt.Errorf("unsupported localization config kind: %s", ref.Kind)
}
Expand Down
Loading

0 comments on commit 9568d38

Please sign in to comment.