Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
frewilhelm committed Feb 13, 2025
1 parent db59c21 commit 2e78025
Show file tree
Hide file tree
Showing 50 changed files with 1,491 additions and 1,213 deletions.
1 change: 0 additions & 1 deletion api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ type ResourceInfo struct {

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
Expand Down
3 changes: 0 additions & 3 deletions api/v1alpha1/component_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ type ComponentStatus struct {
// +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
// fetched after based on the semver constraints during the last successful
// reconciliation.
Expand Down
34 changes: 11 additions & 23 deletions api/v1alpha1/condition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
// CheckVersionFailedReason is used when the controller failed to check for new versions.
CheckVersionFailedReason = "CheckVersionFailed"

// RepositorySpecInvalidReason is used when the referenced repository spec cannot be unmarshaled and therefore is
// RepositorySpecInvalidReason is used when the referenced repository spec cannot be unmarshalled and therefore is
// invalid.
RepositorySpecInvalidReason = "RepositorySpecInvalid"

Expand All @@ -57,27 +57,21 @@ const (
// GetComponentVersionFailedReason is used when the component cannot be fetched.
GetComponentVersionFailedReason = "GetComponentVersionFailed"

// StorageReconcileFailedReason is used when there was a problem reconciling the artifact storage.
StorageReconcileFailedReason = "StorageReconcileFailed"

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

// MarshalFailedReason is used when we fail to marshal a struct.
MarshalFailedReason = "MarshalFailed"

// CreateOCIRepositoryNameFailedReason is used when we fail to create an OCI repository name.
CreateOCIRepositoryNameFailedReason = "CreateOCIRepositoryNameFailed"

// CreateOCIRepositoryFailedReason is used when we fail to create a OCI repository.
// CreateOCIRepositoryFailedReason is used when we fail to create an OCI repository.
CreateOCIRepositoryFailedReason = "CreateOCIRepositoryFailed"

// OCIRepositoryExistsFailedReason is used when we fail to check the existence of an OCI repository.
OCIRepositoryExistsFailedReason = "OCIRepositoryExistsFailed"

// CreateSnapshotFailedReason is used when we fail to create a snapshot.
CreateSnapshotFailedReason = "CreateSnapshotFailed"

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

// GetSnapshotFailedReason is used when we fail in getting a Snapshot.
GetSnapshotFailedReason = "GetSnapshotFailed"

Expand All @@ -99,15 +93,6 @@ const (
// PushSnapshotFailedReason is used when we fail to push a snapshot.
PushSnapshotFailedReason = "PushSnapshotFailed"

// FetchSnapshotFailedReason is used when we fail to fetch a snapshot.
FetchSnapshotFailedReason = "FetchSnapshotFailed"

// DeleteSnapshotFailedReason is used when we fail to delete a snapshot.
DeleteSnapshotFailedReason = "DeleteSnapshotFailed"

// GetComponentForArtifactFailedReason is used when we fail in getting a component for an artifact.
GetComponentForArtifactFailedReason = "GetComponentForArtifactFailed"

// GetComponentForSnapshotFailedReason is used when we fail in getting a component for a snapshot.
GetComponentForSnapshotFailedReason = "GetComponentForSnapshotFailed"

Expand All @@ -120,14 +105,14 @@ const (
// ConfigurationFailedReason is used when a resource was not able to be configured.
ConfigurationFailedReason = "ConfigurationFailed"

// LocalizationRuleGenerationFailedReason is used when the controller failed to localize an artifact.
// LocalizationRuleGenerationFailedReason is used when the controller failed to localize an snapshot.
LocalizationRuleGenerationFailedReason = "LocalizationRuleGenerationFailed"

// LocalizationIsNotReadyReason is used when a controller is waiting to get the localization result.
LocalizationIsNotReadyReason = "LocalizationIsNotReady"

// UniqueIDGenerationFailedReason is used when the controller failed to generate a unique identifier for a pending artifact.
// This can happen if the artifact is based on multiple other sources but these sources could not be used
// UniqueIDGenerationFailedReason is used when the controller failed to generate a unique identifier for a pending snapshot.
// This can happen if the snapshot is based on multiple other sources but these sources could not be used
// to determine a unique identifier.
UniqueIDGenerationFailedReason = "UniqueIDGenerationFailed"

Expand All @@ -138,4 +123,7 @@ const (
// ResourceGenerationFailedReason is used when the controller failed to generate a resource
// based on its specification.
ResourceGenerationFailedReason = "ResourceGenerationFailed"

// Dummy is just a placehold for further TODOs.
Dummy = "DummyFailed"
)
15 changes: 10 additions & 5 deletions api/v1alpha1/configuredresource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/fluxcd/pkg/apis/meta"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -90,13 +91,13 @@ type ConfiguredResourceStatus struct {
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty"`

// The configuration reconcile loop generates an artifact, which contains the
// The configuration reconcile loop generates a snapshot, 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 corev1.LocalObjectReference `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
// Digest contains a technical identifier for the snapshot. This technical identifier
// can be used to track changes on the SnapshotRef as it is a combination of the origin
// ConfiguredResourceSpec.Config applied to the ConfiguredResourceSpec.Target.
Digest string `json:"digest,omitempty"`
}
Expand All @@ -113,6 +114,10 @@ type ConfiguredResource struct {
Status ConfiguredResourceStatus `json:"status,omitempty"`
}

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

// +kubebuilder:object:root=true

// ConfiguredResourceList contains a list of ConfiguredResource.
Expand Down
11 changes: 3 additions & 8 deletions api/v1alpha1/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
OCMConfigKey = ".ocmconfig"
// OCMLabelDowngradable defines the secret.
OCMLabelDowngradable = "ocm.software/ocm-k8s-toolkit/downgradable"
// OCMComponentDescriptorList defines the file name of the component descriptor list exposed as artifact by the
// OCMComponentDescriptorList defines the file name of the component descriptor list exposed as snapshot by the
// component controller.
OCMComponentDescriptorList = "component-descriptor-list.yaml"
)
Expand All @@ -37,16 +37,11 @@ const (

// Finalizers for controllers.
const (
// TODO: Remove ArtifactFinalizer.

// ArtifactFinalizer is the finalizer that is added to artifacts created by the ocm controllers.
ArtifactFinalizer = "finalizers.ocm.software/artifact"

// SnapshotFinalizer is the finalizter that is added to snapshot created by the ocm controllers.
SnapshotFinalizer = "finalizers.ocm.software/snapshot"
)

// External CRDs.
// OCI Schema.
const (
ArtifactCrd = "https://github.com/openfluxcd/artifact/releases/download/v0.1.1/openfluxcd.ocm.software_artifacts.yaml"
OCISchemaVersion = 2
)
13 changes: 9 additions & 4 deletions api/v1alpha1/localizedresource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v1alpha1
import (
"fmt"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -73,6 +74,10 @@ func (in *LocalizedResource) SetTarget(v *ConfigurationReference) {
v.DeepCopyInto(&in.Spec.Target)
}

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

type LocalizedResourceSpec struct {
// Target that is to be localized
Target ConfigurationReference `json:"target"`
Expand All @@ -91,15 +96,15 @@ 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 corev1.LocalObjectReference `json:"snapshotRef,omitempty"`

// The LocalizedResource reports a ConfiguredResourceRef which contains a reference to the ConfiguredResource
// that is responsible for generating the ArtifactRef.
// that is responsible for generating the SnapshotRef.
ConfiguredResourceRef *ObjectKey `json:"configuredResourceRef,omitempty"`

// ConfigRef is a reference to the Configuration that was generated by the Localization process
// and is used to setup the ConfiguredResource responsible for generating the ArtifactRef.
// and is used to setup the ConfiguredResource responsible for generating the SnapshotRef.
ConfigRef *ObjectKey `json:"configRef,omitempty"`

// A unique digest of the combination of the config and target resources applied through a LocalizationStrategy
Expand Down
3 changes: 0 additions & 3 deletions api/v1alpha1/resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ type ResourceStatus struct {
// +optional
SnapshotRef corev1.LocalObjectReference `json:"snapshotRef,omitempty"`

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

// +optional
Resource *ResourceInfo `json:"resource,omitempty"`

Expand Down
14 changes: 2 additions & 12 deletions api/v1alpha1/zz_generated.deepcopy.go

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

47 changes: 14 additions & 33 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,17 @@ import (
"crypto/tls"
"flag"
"os"
"time"

// to ensure that exec-entrypoint and run can make use of them.
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
_ "k8s.io/client-go/plugin/pkg/client/auth"

"github.com/fluxcd/pkg/runtime/events"
"github.com/openfluxcd/controller-manager/server"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/webhook"

artifactv1 "github.com/openfluxcd/artifact/api/v1alpha1"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -64,24 +61,21 @@ func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))

utilruntime.Must(v1alpha1.AddToScheme(scheme))
utilruntime.Must(artifactv1.AddToScheme(scheme))
// +kubebuilder:scaffold:scheme
}

//nolint:funlen,maintidx // this is the main function
//nolint:funlen // this is the main function
func main() {
var (
metricsAddr string
enableLeaderElection bool
probeAddr string
secureMetrics bool
enableHTTP2 bool
artifactRetentionTTL = 60 * time.Second
artifactRetentionRecords = 2
storagePath string
storageAddr string
storageAdvAddr string
eventsAddr string
metricsAddr string
enableLeaderElection bool
probeAddr string
secureMetrics bool
enableHTTP2 bool
storagePath string
storageAddr string
storageAdvAddr string
eventsAddr string
)
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metric endpoint binds to. "+
"Use the port :8080. If not set, it will be 0 in order to disable the metrics server")
Expand Down Expand Up @@ -172,14 +166,6 @@ 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
Expand Down Expand Up @@ -212,7 +198,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 +209,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 All @@ -237,8 +222,8 @@ func main() {
Scheme: mgr.GetScheme(),
EventRecorder: eventsRecorder,
},
Storage: storage,
ConfigClient: cfgclient.NewClientWithLocalStorage(mgr.GetClient(), storage, mgr.GetScheme()),
Registry: registry,
ConfigClient: cfgclient.NewClientWithRegistry(mgr.GetClient(), registry, mgr.GetScheme()),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ConfiguredResource")
os.Exit(1)
Expand Down Expand Up @@ -282,10 +267,6 @@ func main() {
// entire process will terminate if we lose leadership, so we don't need
// to handle that.
<-mgr.Elected()

if err := artifactServer.Start(ctx); err != nil {
setupLog.Error(err, "unable to start artifact server")
}
}()

setupLog.Info("starting manager")
Expand Down
16 changes: 0 additions & 16 deletions config/crd/bases/delivery.ocm.software_components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,22 +180,6 @@ spec:
status:
description: ComponentStatus defines the observed state of Component.
properties:
artifactRef:
description: |-
LocalObjectReference contains enough information to let you locate the
referenced object inside the same namespace.
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
component:
description: |-
Component specifies the concrete version of the component that was
Expand Down
Loading

0 comments on commit 2e78025

Please sign in to comment.