Embed DeploymentSpec
#2948
-
Hello all, Is it possible to embed a appsv1 "k8s.io/api/apps/v1" // ApplicationSpec defines the desired state of Application
type ApplicationSpec struct {
// Kubernetes Deployment Template
Deployment appsv1.Deployment `json:"deployment,omitempty"`
} I have tried this but when I try applying my own custom resource I receive this error: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi @ionut-maxim , Embedding core Kubernetes types, like Your appsv1 "k8s.io/api/apps/v1"
type ApplicationSpec struct {
Deployment appsv1.Deployment `json:"deployment,omitempty"`
} Because of this, the structure of your custom resource should match that of a Deployment when specifying it. However, the error you encountered implies you might have added or missed some fields. If you intended to only embed the DeploymentSpec, you might want to adjust your structure like this: // +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// Application is the Schema for the applications API
type Application struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ApplicationSpec `json:"spec,omitempty"`
Status ApplicationStatus `json:"status,omitempty"`
}
// ApplicationSpec defines the desired state of Application
type ApplicationSpec struct {
DeploymentSpec appsv1.DeploymentSpec `json:"deploymentSpec,omitempty"`
}
// ApplicationStatus defines the observed state of Application
type ApplicationStatus struct {
// Add custom status fields here
} Also, please check the ideal markers for your use case here Marking it as answered but if you need please feel free to re-open. |
Beta Was this translation helpful? Give feedback.
Hi @ionut-maxim ,
Embedding core Kubernetes types, like
DeploymentSpec
, inside your custom resource definition (CRD) is absolutely possible. However, when you do so, you need to be careful with how you structure the objects in your YAML files.Your
ApplicationSpec
structure indicates that you are embedding the entireDeployment
object and not just its spec:Because of this, the structure of your custom resource should match that of a Deployment when specifying it. However, the error you encountered implies you might have added or missed some fields.
If you intended to o…