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

add support for userdata from configmap references #55

Merged
merged 4 commits into from
Jun 7, 2021
Merged

add support for userdata from configmap references #55

merged 4 commits into from
Jun 7, 2021

Conversation

displague
Copy link
Collaborator

@displague displague commented Apr 8, 2021

This PR has a few incomplete changes to incorporate for #54:

  • support for Metros
  • support for userdataRef to load device userdata from configmaps and secrets
  • updates the upbound build/ submodule (and make run)

TODO:

key = configMapKey
}
userdata := cm.Data[key]
d.Spec.ForProvider.UserData = &userdata
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should modify UserData in spec like this, this is acting like a late initialization.

Ultimately, either userdata or userdataRef should be provided.

@@ -135,6 +150,9 @@ type DeviceParameters struct {
// +optional
UserData *string `json:"userdata,omitempty"`

// +optional
UserDataRef *DataKeySelector `json:"userdataRef,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest having a way to differentiate between the kinds, i.e. Secret and ConfigMap, this reference can point to because names are unique at kind level, so there might be unexpected results if there is ConfigMap and Secret with same name and namespace.

For references, we usually go for FieldNameKindRef, like UserDataSecretRef and/or UserDataConfigMapRef.

Another way could be to go for discriminator field, like kind field in DataKeySelector:

// DataKeySelector defines required spec to access a key of a configmap or secret
type DataKeySelector struct {
	NamespacedName `json:",inline,omitempty"`
	// +kubebuilder:validation:Enum=Secret;ConfigMap
	Kind           string `json:"kind"`
	Key            string `json:"key"`
	Optional       bool   `json:"optional,omitempty"`
}

@@ -182,6 +189,36 @@ func (e *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext

d.Status.SetConditions(runtimev1alpha1.Creating())

// TODO(displague) clean up this hack to demonstrate userdataRef
if d.Spec.ForProvider.UserDataRef != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use reference resolver mechanism from crossplane-runtime that will take care of this before your functions are called. See an example here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@muvaf It looks like reference.Resolve can only work with cluster scoped resources because the Reference field wants a *xpv1.Reference (name only). Perhaps that could be modified to an interface in the future to accommodate SecretReference, TypedReference, and others. I think a TypedReference is what I would use here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that's true! It's designed for finding other managed resource.

@displague
Copy link
Collaborator Author

how should userdata changes trigger the device to reprovision? Should this be indicated with spec level (not forProvider level) options? crossplane/crossplane#2258

There are parallels to this question in packethost/terraform-provider-packet#77 where the intent to reprovision an existing device is desired, without DELETE'ing the resource. Some otherwise immutable features become mutable through EM API /device/{id}/actions.

displague added 4 commits June 1, 2021 09:11
Signed-off-by: Marques Johansson <mjohansson@equinix.com>
Signed-off-by: Marques Johansson <mjohansson@equinix.com>
Signed-off-by: Marques Johansson <mjohansson@equinix.com>
Signed-off-by: Marques Johansson <mjohansson@equinix.com>
@displague displague changed the title WIP: add support for userdata from configmap references add support for userdata from configmap references Jun 1, 2021
@displague displague marked this pull request as ready for review June 1, 2021 18:42
@displague displague merged commit 2492903 into crossplane-contrib:master Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants