Skip to content

Commit

Permalink
replace storage with oci artifact for component controller
Browse files Browse the repository at this point in the history
  • Loading branch information
frewilhelm committed Feb 3, 2025
1 parent d845734 commit cbe7736
Show file tree
Hide file tree
Showing 24 changed files with 486 additions and 1,302 deletions.
13 changes: 13 additions & 0 deletions api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,16 @@ type ResourceInfo struct {
// +required
Digest string `json:"digest,omitempty"`
}

type BlobInfo struct {
// Digest is the digest of the blob in the form of '<algorithm>:<checksum>'.
// +kubebuilder:validation:Pattern="^[a-z0-9]+(?:[.+_-][a-z0-9]+)*:[a-zA-Z0-9=_-]+$"
Digest string `json:"digest"`

// Tag/Version of the blob
Tag string `json:"tag"`

// Size is the number of bytes of the blob.
// Can be used to determine how to file should be handled when downloaded (memory/disk)
Size int64 `json:"size"`
}
9 changes: 8 additions & 1 deletion api/v1alpha1/component_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@ type ComponentStatus struct {
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty"`

// ArtifactRef references the generated artifact containing a list of
// SnapshotRef references the generated snapshot containing a list of
// component descriptors. This list can be used by other controllers to
// avoid re-downloading (and potentially also re-verifying) the components.
// +optional
SnapshotRef corev1.LocalObjectReference `json:"snapshotRef,omitempty"`

// TODO: Remove
ArtifactRef corev1.LocalObjectReference `json:"artifactRef,omitempty"`

// Component specifies the concrete version of the component that was
Expand Down Expand Up @@ -180,6 +183,10 @@ func (in *Component) GetVerifications() []Verification {
return in.Spec.Verify
}

func (in *Component) GetSnapshotName() string {
return in.Status.SnapshotRef.Name
}

// +kubebuilder:object:root=true

// ComponentList contains a list of Component.
Expand Down
12 changes: 10 additions & 2 deletions api/v1alpha1/resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ type ResourceStatus struct {
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty"`

// ArtifactRef points to the Artifact which represents the output of the
// last successful Resource sync.
// SnapshotRef references the generated snapshot containing a list of
// component descriptors. This list can be used by other controllers to
// avoid re-downloading (and potentially also re-verifying) the components.
// +optional
SnapshotRef corev1.LocalObjectReference `json:"snapshotRef,omitempty"`

// TODO: Remove
ArtifactRef corev1.LocalObjectReference `json:"artifactRef,omitempty"`

// +optional
Expand Down Expand Up @@ -131,6 +135,10 @@ func (in *Resource) GetEffectiveOCMConfig() []OCMConfiguration {
return in.Status.EffectiveOCMConfig
}

func (in *Resource) GetSnapshotName() string {
return in.Status.SnapshotRef.Name
}

// +kubebuilder:object:root=true

// ResourceList contains a list of Resource.
Expand Down
30 changes: 11 additions & 19 deletions api/v1alpha1/snapshot_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,31 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ocmmetav1 "ocm.software/ocm/api/ocm/compdesc/meta/v1"
)

// SnapshotWriter defines any object which produces a snapshot
// +k8s:deepcopy-gen=false
type SnapshotWriter interface {
client.Object
GetSnapshotDigest() string
GetSnapshotName() string
GetKind() string
GetNamespace() string
GetName() string
}

// SnapshotSpec defines the desired state of Snapshot.
type SnapshotSpec struct {
Identity ocmmetav1.Identity `json:"identity"`
// OCI repository name
// +required
Repository string `json:"repository"`

// Manifest digest
// +required
Digest string `json:"digest"`

Tag string `json:"tag"`
// Blob
// +required
Blob BlobInfo `json:"blob"`

// Suspend stops all operations on this object.
// +optional
Expand All @@ -41,10 +48,6 @@ type SnapshotStatus struct {
// +optional
LastReconciledTag string `json:"tag,omitempty"`

// RepositoryURL has the concrete URL pointing to the local registry including the service name.
// +optional
RepositoryURL string `json:"repositoryURL,omitempty"`

// ObservedGeneration is the last reconciled generation.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
Expand All @@ -61,17 +64,6 @@ func (in *Snapshot) SetObservedGeneration(v int64) {
in.Status.ObservedGeneration = v
}

// TODO: Check purpose
//// GetComponentVersion returns the component version for the snapshot.
// func (in Snapshot) GetComponentVersion() string {
// return in.Spec.Identity[ComponentVersionKey]
//}
//
//// GetComponentResourceVersion returns the resource version for the snapshot.
// func (in Snapshot) GetComponentResourceVersion() string {
// return in.Spec.Identity[ResourceVersionKey]
//}

// GetDigest returns the last reconciled digest for the snapshot.
func (in Snapshot) GetDigest() string {
return in.Status.LastReconciledDigest
Expand Down
27 changes: 19 additions & 8 deletions api/v1alpha1/zz_generated.deepcopy.go

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

19 changes: 17 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import (
"github.com/open-component-model/ocm-k8s-toolkit/internal/controller/resource"
"github.com/open-component-model/ocm-k8s-toolkit/internal/controller/snapshot"
"github.com/open-component-model/ocm-k8s-toolkit/pkg/ocm"
snapshotRegistry "github.com/open-component-model/ocm-k8s-toolkit/pkg/snapshot"
)

var (
Expand All @@ -67,7 +68,7 @@ func init() {
// +kubebuilder:scaffold:scheme
}

//nolint:funlen // this is the main function
//nolint:funlen,maintidx // this is the main function
func main() {
var (
metricsAddr string
Expand Down Expand Up @@ -171,20 +172,34 @@ func main() {
os.Exit(1)
}

// TODO: Replace
storage, artifactServer, err := server.NewArtifactStore(mgr.GetClient(), mgr.GetScheme(),
storagePath, storageAddr, storageAdvAddr, artifactRetentionTTL, artifactRetentionRecords)
if err != nil {
setupLog.Error(err, "unable to initialize storage")
os.Exit(1)
}

// TODO: Adjust hardcode with CLI param
registry, err := snapshotRegistry.NewRegistry("ocm-k8s-toolkit-zot-registry.ocm-k8s-toolkit-system.svc.cluster.local:5000")
registry.PlainHTTP = true
if err != nil {
setupLog.Error(err, "unable to initialize registry object")
os.Exit(1)
}

if err := registry.Ping(ctx); err != nil {
setupLog.Error(err, "unable to ping OCI registry")
os.Exit(1)
}

if err = (&component.Reconciler{
BaseReconciler: &ocm.BaseReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
EventRecorder: eventsRecorder,
},
Storage: storage,
Registry: registry,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Component")
os.Exit(1)
Expand Down
22 changes: 19 additions & 3 deletions config/crd/bases/delivery.ocm.software_components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,8 @@ spec:
properties:
artifactRef:
description: |-
ArtifactRef references the generated artifact containing a list of
component descriptors. This list can be used by other controllers to
avoid re-downloading (and potentially also re-verifying) the components.
LocalObjectReference contains enough information to let you locate the
referenced object inside the same namespace.
properties:
name:
default: ""
Expand Down Expand Up @@ -327,6 +326,23 @@ spec:
object.
format: int64
type: integer
snapshotRef:
description: |-
SnapshotRef references the generated snapshot containing a list of
component descriptors. This list can be used by other controllers to
avoid re-downloading (and potentially also re-verifying) the components.
properties:
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
type: object
x-kubernetes-map-type: atomic
type: object
required:
- spec
Expand Down
21 changes: 19 additions & 2 deletions config/crd/bases/delivery.ocm.software_resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ spec:
properties:
artifactRef:
description: |-
ArtifactRef points to the Artifact which represents the output of the
last successful Resource sync.
LocalObjectReference contains enough information to let you locate the
referenced object inside the same namespace.
properties:
name:
default: ""
Expand Down Expand Up @@ -300,6 +300,23 @@ spec:
- name
- type
type: object
snapshotRef:
description: |-
SnapshotRef references the generated snapshot containing a list of
component descriptors. This list can be used by other controllers to
avoid re-downloading (and potentially also re-verifying) the components.
properties:
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
type: object
x-kubernetes-map-type: atomic
type: object
required:
- spec
Expand Down
42 changes: 27 additions & 15 deletions config/crd/bases/delivery.ocm.software_snapshots.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,40 @@ spec:
spec:
description: SnapshotSpec defines the desired state of Snapshot.
properties:
blob:
description: Blob
properties:
digest:
description: Digest is the digest of the blob in the form of '<algorithm>:<checksum>'.
pattern: ^[a-z0-9]+(?:[.+_-][a-z0-9]+)*:[a-zA-Z0-9=_-]+$
type: string
size:
description: |-
Size is the number of bytes of the blob.
Can be used to determine how to file should be handled when downloaded (memory/disk)
format: int64
type: integer
tag:
description: Tag/Version of the blob
type: string
required:
- digest
- size
- tag
type: object
digest:
description: Manifest digest
type: string
repository:
description: OCI repository name
type: string
identity:
additionalProperties:
type: string
description: |-
Identity describes the identity of an object.
Only ascii characters are allowed
type: object
suspend:
description: Suspend stops all operations on this object.
type: boolean
tag:
type: string
required:
- blob
- digest
- identity
- tag
- repository
type: object
status:
description: SnapshotStatus defines the observed state of Snapshot.
Expand Down Expand Up @@ -133,10 +149,6 @@ spec:
description: ObservedGeneration is the last reconciled generation.
format: int64
type: integer
repositoryURL:
description: RepositoryURL has the concrete URL pointing to the local
registry including the service name.
type: string
tag:
description: Tag defines the explicit tag that was used to create
the related snapshot and cache entry.
Expand Down
Loading

0 comments on commit cbe7736

Please sign in to comment.