-
Notifications
You must be signed in to change notification settings - Fork 8
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
Conversation
key = configMapKey | ||
} | ||
userdata := cm.Data[key] | ||
d.Spec.ForProvider.UserData = &userdata |
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There are parallels to this question in packethost/terraform-provider-packet#77 where the intent to reprovision an existing device is desired, without |
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>
This PR has a few incomplete changes to incorporate for #54:
make run
)TODO:
how should userdata changes trigger the device to reprovision? Should this be indicated with
spec
level (notforProvider
level) options? Document best practice for external resource updates that require delete + create crossplane/crossplane#2258Update: this is less destructive with
POST /devices/{id}/actions { "type": "reinstall" }
https://metal.equinix.com/developers/docs/resilience-recovery/reinstall/