Skip to content

Commit

Permalink
Merge pull request #353 from MisterMX/composite-environment
Browse files Browse the repository at this point in the history
feat(composite):  Add support for EnvironmentConfigs
  • Loading branch information
negz committed Sep 7, 2022
2 parents d9c25ae + dfd4687 commit 619edba
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/resource/fake/mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ func (m *ComposedResourcesReferencer) SetResourceReferences(r []corev1.ObjectRef
// GetResourceReferences gets the composed references.
func (m *ComposedResourcesReferencer) GetResourceReferences() []corev1.ObjectReference { return m.Refs }

type EnvironmentConfigReferencer struct{ Refs []corev1.ObjectReference }

// SetEnvironmentConfigReferences sets the EnvironmentConfig references.
func (m *EnvironmentConfigReferencer) SetEnvironmentConfigReferences(refs []corev1.ObjectReference) {
m.Refs = refs
}

// GetEnvironmentConfigReferences gets the EnvironmentConfig references.
func (m *EnvironmentConfigReferencer) GetEnvironmentConfigReferences() []corev1.ObjectReference {
return m.Refs
}

// ConnectionDetailsLastPublishedTimer is a mock that implements the
// ConnectionDetailsLastPublishedTimer interface.
type ConnectionDetailsLastPublishedTimer struct{ Time *metav1.Time }
Expand Down Expand Up @@ -307,6 +319,7 @@ type Composite struct {
CompositionRevisionReferencer
CompositionUpdater
ComposedResourcesReferencer
EnvironmentConfigReferencer
ClaimReferencer
ConnectionSecretWriterTo
ConnectionDetailsPublisherTo
Expand Down
7 changes: 7 additions & 0 deletions pkg/resource/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ type CompositeResourceReferencer interface {
GetResourceReference() *corev1.ObjectReference
}

// An EnvironmentConfigReferencer references a list of EnvironmentConfigs.
type EnvironmentConfigReferencer interface {
SetEnvironmentConfigReferences([]corev1.ObjectReference)
GetEnvironmentConfigReferences() []corev1.ObjectReference
}

// A UserCounter can count how many users it has.
type UserCounter interface {
SetUsers(i int64)
Expand Down Expand Up @@ -216,6 +222,7 @@ type Composite interface {
CompositionUpdater
CompositionRevisionReferencer
ComposedResourcesReferencer
EnvironmentConfigReferencer
ClaimReferencer
ConnectionSecretWriterTo
ConnectionDetailsPublisherTo
Expand Down
22 changes: 22 additions & 0 deletions pkg/resource/unstructured/composite/composite.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,25 @@ func (c *Unstructured) GetConnectionDetailsLastPublishedTime() *metav1.Time {
func (c *Unstructured) SetConnectionDetailsLastPublishedTime(t *metav1.Time) {
_ = fieldpath.Pave(c.Object).SetValue("status.connectionDetails.lastPublishedTime", t)
}

// GetEnvironmentConfigReferences of this Composite resource.
func (c *Unstructured) GetEnvironmentConfigReferences() []corev1.ObjectReference {
out := &[]corev1.ObjectReference{}
_ = fieldpath.Pave(c.Object).GetValueInto("spec.environmentConfigRefs", out)
return *out
}

// SetEnvironmentConfigReferences of this Composite resource.
func (c *Unstructured) SetEnvironmentConfigReferences(refs []corev1.ObjectReference) {
empty := corev1.ObjectReference{}
filtered := make([]corev1.ObjectReference, 0, len(refs))
for _, ref := range refs {
// TODO(negz): Ask muvaf to explain what this is working around. :)
// TODO(muvaf): temporary workaround.
if ref.String() == empty.String() {
continue
}
filtered = append(filtered, ref)
}
_ = fieldpath.Pave(c.Object).SetValue("spec.resourceRefs", filtered)
}

0 comments on commit 619edba

Please sign in to comment.