Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rework selectors #858

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmds/ocm/commands/ocmcmds/pubsub/get/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (o *Command) ForName(name string) *cobra.Command {
Short: "Get the pubsub spec for an ocm repository",
Long: `
A repository may be able to store a publish/subscribe specification
to propagate the creation or update of component version.
to propagate the creation or update of component versions.
If such an implementation is available and a specification is
assigned to the repository, it is shown. The specification
can be set with the <CMD>ocm set pubsub</CMD>.
Expand Down
2 changes: 1 addition & 1 deletion cmds/ocm/commands/ocmcmds/pubsub/set/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (o *Command) ForName(name string) *cobra.Command {
Short: "Set the pubsub spec for an ocm repository",
Long: `
A repository may be able to store a publish/subscribe specification
to propagate the creation or update of component version.
to propagate the creation or update of component versions.
If such an implementation is available this command can be used
to set the pub/sub specification for a repository.
If no specification is given an existing specification
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/ocm_get_pubsub.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pubsub, ps


A repository may be able to store a publish/subscribe specification
to propagate the creation or update of component version.
to propagate the creation or update of component versions.
If such an implementation is available and a specification is
assigned to the repository, it is shown. The specification
can be set with the [ocm set pubsub](ocm_set_pubsub.md).
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ require (
github.com/go-openapi/strfmt v0.23.0
github.com/go-openapi/swag v0.23.0
github.com/go-test/deep v1.1.0
github.com/gobwas/glob v0.2.3
github.com/golang/mock v1.6.0
github.com/google/go-github/v45 v45.2.0
github.com/hashicorp/vault-client-go v0.4.3
Expand Down Expand Up @@ -193,7 +194,6 @@ require (
github.com/go-openapi/spec v0.21.0 // indirect
github.com/go-openapi/validate v0.24.0 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/goccy/go-yaml v1.11.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
Expand Down
84 changes: 84 additions & 0 deletions pkg/contexts/ocm/compdesc/accessors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package compdesc

import (
"github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/equivalent"
metav1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1"
"github.com/open-component-model/ocm/pkg/contexts/ocm/selectors/accessors"
)

// NameAccessor describes a accessor for a named object.
type NameAccessor interface {
// GetName returns the name of the object.
GetName() string
// SetName sets the name of the object.
SetName(name string)
}

// VersionAccessor describes a accessor for a versioned object.
type VersionAccessor interface {
// GetVersion returns the version of the object.
GetVersion() string
// SetVersion sets the version of the object.
SetVersion(version string)
}

// LabelsAccessor describes a accessor for a labeled object.
type LabelsAccessor interface {
// GetLabels returns the labels of the object.
GetLabels() metav1.Labels
// SetLabels sets the labels of the object.
SetLabels(labels []metav1.Label)
}

// ObjectMetaAccessor describes a accessor for named and versioned object.
type ObjectMetaAccessor interface {
NameAccessor
VersionAccessor
LabelsAccessor
}

// ElementMetaAccessor provides generic access an elements meta information.
type ElementMetaAccessor interface {
ElementMetaProvider
Equivalent(ElementMetaAccessor) equivalent.EqualState
}

// ElementAccessor provides generic access to list of elements.
type ElementAccessor interface {
Len() int
Get(i int) ElementMetaAccessor
}

type ElementMetaProvider interface {
GetMeta() *ElementMeta
}

// ElementArtifactAccessor provides access to generic artifact information of an element.
type ElementArtifactAccessor interface {
ElementMetaAccessor
GetType() string
GetAccess() AccessSpec
SetAccess(a AccessSpec)
}

type ElementDigestAccessor interface {
GetDigest() *metav1.DigestSpec
SetDigest(*metav1.DigestSpec)
}

// ArtifactAccessor provides generic access to list of artifacts.
// There are resources or sources.
type ArtifactAccessor interface {
ElementAccessor
GetArtifact(i int) ElementArtifactAccessor
}

// AccessSpec is an abstract specification of an access method
// The outbound object is typicall a runtime.UnstructuredTypedObject.
// Inbound any serializable AccessSpec implementation is possible.
type AccessSpec = accessors.AccessSpec

// AccessProvider provides access to an access specification of elements.
type AccessProvider interface {
GetAccess() AccessSpec
}
113 changes: 32 additions & 81 deletions pkg/contexts/ocm/compdesc/componentdescriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/equivalent"
metav1 "github.com/open-component-model/ocm/pkg/contexts/ocm/compdesc/meta/v1"
"github.com/open-component-model/ocm/pkg/contexts/ocm/selectors/accessors"
"github.com/open-component-model/ocm/pkg/runtime"
"github.com/open-component-model/ocm/pkg/semverutils"
)
Expand Down Expand Up @@ -112,8 +113,8 @@ type ComponentSpec struct {
}

const (
SystemIdentityName = "name"
SystemIdentityVersion = "version"
SystemIdentityName = metav1.SystemIdentityName
SystemIdentityVersion = metav1.SystemIdentityVersion
)

type ElementMetaAccess interface {
Expand Down Expand Up @@ -247,6 +248,31 @@ func (o *ElementMeta) GetIdentity(accessor ElementAccessor) metav1.Identity {
return identity
}

// GetIdentityForContext returns the identity of the object.
func (o *ElementMeta) GetIdentityForContext(accessor accessors.ElementListAccessor) metav1.Identity {
identity := o.ExtraIdentity.Copy()
if identity == nil {
identity = metav1.Identity{}
}
identity[SystemIdentityName] = o.Name
if accessor != nil {
found := false
l := accessor.Len()
for i := 0; i < l; i++ {
m := accessor.Get(i).GetMeta()
if m.GetName() == o.GetName() && m.GetExtraIdentity().Equals(o.ExtraIdentity) {
if found {
identity[SystemIdentityVersion] = o.Version

break
}
found = true
}
}
}
return identity
}

// GetRawIdentity returns the identity plus version.
func (o *ElementMeta) GetRawIdentity() metav1.Identity {
identity := o.ExtraIdentity.Copy()
Expand Down Expand Up @@ -304,43 +330,6 @@ func (o *ElementMeta) Equivalent(a *ElementMeta) equivalent.EqualState {
return state.Apply(o.Labels.Equivalent(a.Labels))
}

// NameAccessor describes a accessor for a named object.
type NameAccessor interface {
// GetName returns the name of the object.
GetName() string
// SetName sets the name of the object.
SetName(name string)
}

// VersionAccessor describes a accessor for a versioned object.
type VersionAccessor interface {
// GetVersion returns the version of the object.
GetVersion() string
// SetVersion sets the version of the object.
SetVersion(version string)
}

// LabelsAccessor describes a accessor for a labeled object.
type LabelsAccessor interface {
// GetLabels returns the labels of the object.
GetLabels() metav1.Labels
// SetLabels sets the labels of the object.
SetLabels(labels []metav1.Label)
}

// ObjectMetaAccessor describes a accessor for named and versioned object.
type ObjectMetaAccessor interface {
NameAccessor
VersionAccessor
LabelsAccessor
}

// ElementMetaAccessor provides generic access an elements meta information.
type ElementMetaAccessor interface {
ElementMetaProvider
Equivalent(ElementMetaAccessor) equivalent.EqualState
}

func GetByIdentity(a ElementAccessor, id metav1.Identity) ElementMetaAccessor {
l := a.Len()
for i := 0; i < l; i++ {
Expand All @@ -363,47 +352,10 @@ func GetIndexByIdentity(a ElementAccessor, id metav1.Identity) int {
return -1
}

// ElementAccessor provides generic access to list of elements.
type ElementAccessor interface {
Len() int
Get(i int) ElementMetaAccessor
}

type ElementMetaProvider interface {
GetMeta() *ElementMeta
}

// ElementArtifactAccessor provides access to generic artifact information of an element.
type ElementArtifactAccessor interface {
ElementMetaAccessor
GetType() string
GetAccess() AccessSpec
SetAccess(a AccessSpec)
}

type ElementDigestAccessor interface {
GetDigest() *metav1.DigestSpec
SetDigest(*metav1.DigestSpec)
}

// ArtifactAccessor provides generic access to list of artifacts.
// There are resources or sources.
type ArtifactAccessor interface {
ElementAccessor
GetArtifact(i int) ElementArtifactAccessor
}

// ArtifactAccess provides access to a dedicated kind of artifact set
// in the component descriptor (resources or sources).
type ArtifactAccess func(cd *ComponentDescriptor) ArtifactAccessor

// AccessSpec is an abstract specification of an access method
// The outbound object is typicall a runtime.UnstructuredTypedObject.
// Inbound any serializable AccessSpec implementation is possible.
type AccessSpec interface {
runtime.VersionedTypedObject
}

// GenericAccessSpec returns a generic AccessSpec implementation for an unstructured object.
// It can always be used instead of a dedicated access spec implementation. The core
// methods will map these spec into effective ones before an access is returned to the caller.
Expand All @@ -413,11 +365,6 @@ func GenericAccessSpec(un *runtime.UnstructuredTypedObject) AccessSpec {
}
}

// AccessProvider provides access to an access specification of elements.
type AccessProvider interface {
GetAccess() AccessSpec
}

// Sources describes a set of source specifications.
type Sources []Source

Expand Down Expand Up @@ -652,6 +599,10 @@ func (r *Resource) SetDigest(d *metav1.DigestSpec) {
r.Digest = d
}

func (r *Resource) GetRelation() metav1.ResourceRelation {
return r.Relation
}

func (r *Resource) Equivalent(e ElementMetaAccessor) equivalent.EqualState {
if o, ok := e.(*Resource); !ok {
state := equivalent.StateNotLocalHashEqual()
Expand Down
Loading
Loading