Skip to content

Commit

Permalink
Implement resource controller
Browse files Browse the repository at this point in the history
  • Loading branch information
frewilhelm committed Oct 7, 2024
1 parent b007158 commit 725d4ef
Show file tree
Hide file tree
Showing 13 changed files with 982 additions and 181 deletions.
11 changes: 6 additions & 5 deletions api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ type Verification struct {
// ResourceID defines the configuration of the repository.
type ResourceID struct {
// +required
ByReference ocmv1.ResourceReference `json:"byReference,omitempty"`
// TODO: Implement ByPath (ByPath should be parsed to a ResourceReference
// +optional
ByPath string `json:"byPath,omitempty"`
ByReference ResourceReference `json:"byReference,omitempty"`
// TODO: Implement BySelector
//BySelector any `json:"bySelector,omitempty"`
}

type ResourceReference struct {
Resource ocmv1.Identity `json:"resource,omitempty"`

Check failure on line 58 in api/v1alpha1/common_types.go

View workflow job for this annotation

GitHub Actions / Check for diff

unknown type ocmv1.Identity

Check failure on line 58 in api/v1alpha1/common_types.go

View workflow job for this annotation

GitHub Actions / run-test-suite

unknown type ocmv1.Identity
ReferencePath []ocmv1.Identity `json:"referencePath,omitempty"`

Check failure on line 59 in api/v1alpha1/common_types.go

View workflow job for this annotation

GitHub Actions / Check for diff

unknown type ocmv1.Identity

Check failure on line 59 in api/v1alpha1/common_types.go

View workflow job for this annotation

GitHub Actions / run-test-suite

unknown type ocmv1.Identity
}

type ComponentInfo struct {
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/component_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ type ComponentStatus struct {
// +optional
ArtifactRef corev1.LocalObjectReference `json:"artifactRef,omitempty"`
// +optional
Artifact artifactv1.ArtifactSpec `json:"artifact,omitempty"`
Artifact *artifactv1.ArtifactSpec `json:"artifact,omitempty"`
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty"`
// +optional
Component ComponentInfo `json:"component,omitempty"`
Component *ComponentInfo `json:"component,omitempty"`
// Propagate its effective secrets. Other controllers (e.g. Resource controller) may use this as default
// if they do not explicitly refer a secret.
// +optional
Expand Down
45 changes: 45 additions & 0 deletions api/v1alpha1/condition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const (
// RepositoryIsNotReadyReason is used when the referenced repository is not Ready yet.
RepositoryIsNotReadyReason = "RepositoryIsNotReady"

// GetRepositoryFailedReason is used when the repository cannot be fetched.
GetRepositoryFailedReason = "GetRepositoryFailed"

// ComponentIsNotReadyReason is used when the referenced component is not Ready yet.
ComponentIsNotReadyReason = "ComponentIsNotReady"

Expand All @@ -51,6 +54,9 @@ const (
// ListComponentDescriptorsFailedReason is used when the components cannot be listed.
ListComponentDescriptorsFailedReason = "ListComponentDescriptorsFailed"

// GetComponentDescriptorsFailedReason is used when the component descriptor cannot be fetched.
GetComponentDescriptorsFailedReason = "GetComponentDescriptorsFailed"

// GetComponentVersionFailedReason is used when the component cannot be fetched.
GetComponentVersionFailedReason = "GetComponentVersionFailed"

Expand All @@ -66,9 +72,48 @@ const (
// MarshallingComponentDescriptorsFailedReason is used when we can't serialize the component descriptor list.
MarshallingComponentDescriptorsFailedReason = "MarshallingComponentDescriptorsFailed"

// UnmarshallingComponentDescriptorsFailedReason is used when we can't serialize the component descriptor list.
UnmarshallingComponentDescriptorsFailedReason = "UnmarshallingComponentDescriptorsFailed"

// WritingComponentFileFailedReason is used when we fail to create the file for the component descriptors.
WritingComponentFileFailedReason = "WritingComponentFileFailed"

// ReconcileArtifactFailedReason is used when we fail in creating an Artifact.
ReconcileArtifactFailedReason = "ReconcileArtifactFailed"

// GetArtifactFailedReason is used when we fail in getting an Artifact.
GetArtifactFailedReason = "GetArtifactFailed"

// ResolveResourceFailedReason is used when we fail in resolving a resource.
ResolveResourceFailedReason = "ResolveResourceFailed"

// GetResourceReaderFailedReason is used when we fail in getting a resource reader.
GetResourceReaderFailedReason = "GetResourceReaderFailed"

// GetResourceAccessFailedReason is used when we fail in getting a resource access(es).
GetResourceAccessFailedReason = "GetResourceAccessFailed"

// GetResourceAccessDataFailedReason is used when we fail in getting a resource access data.
GetResourceAccessDataFailedReason = "GetResourceAccessDataFailed"

// DigestVerificationFailedReason is used when we fail in verifying the digest.
DigestVerificationFailedReason = "DigestVerificationFailed"

// CreateHttpRequestFailedReason is used when we fail in creating an HttpRequest.
CreateHTTPRequestFailedReason = "GetHttpRequestFailed"

// ExecHttpRequestFailedReason is used when we fail in executing an HttpRequest.
ExecHTTPRequestFailedReason = "ExecHttpRequestFailed"

// UntarFailedReason is used when we fail in untaring.
UntarFailedReason = "UntarFailed"

// ReadFileFailedReason is used when we fail in reading a file.
ReadFileFailedReason = "ReadFileFailed"

// OpenFileFailedReason is used when we fail in opening a file.
OpenFileFailedReason = "OpenFileFailed"

// CopyFileFailedReason is used when we fail in copying a file.
CopyFileFailedReason = "CopyFileFailed"
)
12 changes: 3 additions & 9 deletions api/v1alpha1/resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import (

// ResourceSpec defines the desired state of Resource.
type ResourceSpec struct {
// +required
RepositoryRef ObjectKey `json:"repositoryRef"`
// +required
ComponentRef ObjectKey `json:"componentRef"`
// +required
Expand Down Expand Up @@ -68,13 +66,13 @@ type ResourceStatus struct {
// +optional
ArtifactRef v1.LocalObjectReference `json:"artifactRef,omitempty"`
// +optional
Artifact artifactv1.ArtifactSpec `json:"artifact,omitempty"`
Artifact *artifactv1.ArtifactSpec `json:"artifact,omitempty"`
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty"`
// +optional
Component ComponentInfo `json:"component,omitempty"`
Component *ComponentInfo `json:"component,omitempty"`
// +optional
Resource ResourceInfo `json:"resource,omitempty"`
Resource *ResourceInfo `json:"resource,omitempty"`
// Propagate its effective secrets. Other controllers (e.g. Resource controller) may use this as default
// if they do not explicitly refer a secret.
// +optional
Expand Down Expand Up @@ -112,25 +110,21 @@ func (in *Resource) SetConditions(conditions []metav1.Condition) {
}

func (in *Resource) GetVID() map[string]string {
// TODO: Check if ID is unique
vid := fmt.Sprintf("%s:%s", in.Status.Resource.Name, in.Status.Resource.Version)
metadata := make(map[string]string)
metadata[GroupVersion.Group+"/resource_version"] = vid

return metadata
}

// TODO: Check if necessary
func (in *Resource) SetObservedGeneration(v int64) {
in.Status.ObservedGeneration = v
}

// TODO: Check if necessary
func (in *Resource) GetObjectMeta() *metav1.ObjectMeta {
return &in.ObjectMeta
}

// TODO: Check if necessary
func (in *Resource) GetKind() string {
return "Resource"
}
Expand Down
78 changes: 67 additions & 11 deletions api/v1alpha1/zz_generated.deepcopy.go

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

36 changes: 19 additions & 17 deletions config/crd/bases/delivery.ocm.software_resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,30 @@ spec:
type: string
interval:
type: string
repositoryRef:
properties:
name:
type: string
namespace:
type: string
required:
- name
type: object
resource:
description: ResourceID defines the configuration of the repository.
properties:
extraIdentity:
additionalProperties:
type: string
byReference:
properties:
referencePath:
items:
additionalProperties:
type: string
description: |-
Identity describes the identity of an object.
Only ascii characters are allowed
type: object
type: array
resource:
additionalProperties:
type: string
description: |-
Identity describes the identity of an object.
Only ascii characters are allowed
type: object
type: object
name:
description: a v1.ResourceReference
type: string
required:
- name
- byReference
type: object
resourceSelector:
x-kubernetes-preserve-unknown-fields: true
Expand All @@ -122,7 +125,6 @@ spec:
required:
- componentRef
- interval
- repositoryRef
- resource
type: object
status:
Expand Down
Loading

0 comments on commit 725d4ef

Please sign in to comment.