Skip to content

Commit

Permalink
Add preserve unkwn fields to pod metadata spec (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
jthomperoo committed Jul 3, 2022
1 parent a9041df commit 1efee1a
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 25 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ jobs:
version: 'v3.9.0'
id: helm

- name: Get build dependencies
run: |
# controller-gen
CONTROLLER_GEN_TMP_DIR=$(mktemp -d)
cd $CONTROLLER_GEN_TMP_DIR
go mod init tmp
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.9.2
rm -rf $CONTROLLER_GEN_TMP_DIR
- name: Check out code into the Go module directory
uses: actions/checkout@v1

Expand All @@ -38,7 +29,6 @@ jobs:
- name: Lint, unit test and build
run: |
export PATH=$PATH:$(go env GOPATH)/bin
go install golang.org/x/lint/golint@v0.0.0-20201208152925-83fdc39ff7b5
make vendor_modules
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Fixed bug that pod metadata was not preserved when creating the pod ([#87](https://github.com/jthomperoo/custom-pod-autoscaler-operator/issues/87)).

## [v1.2.1] - 2022-04-17
### Fixed
- Fixed issue with namespaced deploys not working due to invalid permissions when watching resources in a namespace.
Expand Down
19 changes: 18 additions & 1 deletion api/v1/custompodautoscaler_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type CustomPodAutoscalerConfig struct {
// CustomPodAutoscalerSpec defines the desired state of CustomPodAutoscaler
type CustomPodAutoscalerSpec struct {
// The image of the Custom Pod Autoscaler
Template corev1.PodTemplateSpec `json:"template"`
Template PodTemplateSpec `json:"template"`
// ScaleTargetRef defining what the Custom Pod Autoscaler should manage
ScaleTargetRef autoscaling.CrossVersionObjectReference `json:"scaleTargetRef"`
// Configuration options to be delivered as environment variables to the container
Expand Down Expand Up @@ -74,6 +74,23 @@ type CustomPodAutoscalerList struct {
Items []CustomPodAutoscaler `json:"items"`
}

type PodTemplateSpec struct {
// Standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
ObjectMeta PodMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

// Specification of the desired behavior of the pod.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
// +optional
Spec PodSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
}

// +kubebuilder:pruning:PreserveUnknownFields
type PodMeta metav1.ObjectMeta

type PodSpec corev1.PodSpec

func init() {
SchemeBuilder.Register(&CustomPodAutoscaler{}, &CustomPodAutoscalerList{})
}
233 changes: 233 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions controllers/custompodautoscaler_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ func (r *CustomPodAutoscalerReconciler) Reconcile(context context.Context, req c

// Define Pod object with ObjectMeta and modified PodSpec
pod := &corev1.Pod{
ObjectMeta: objectMeta,
Spec: podSpec,
ObjectMeta: metav1.ObjectMeta(objectMeta),
Spec: corev1.PodSpec(podSpec),
}
result, err = r.KubernetesResourceReconciler.Reconcile(reqLogger, instance, pod, *instance.Spec.ProvisionPod, false)
if err != nil {
Expand Down
24 changes: 12 additions & 12 deletions controllers/custompodautoscaler_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func TestReconcile(t *testing.T) {
}()).WithRuntimeObjects(
&custompodautoscalercomv1.CustomPodAutoscaler{
Spec: custompodautoscalercomv1.CustomPodAutoscalerSpec{
Template: corev1.PodTemplateSpec{},
Template: custompodautoscalercomv1.PodTemplateSpec{},
},
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Expand Down Expand Up @@ -422,8 +422,8 @@ func TestReconcile(t *testing.T) {
}()).WithRuntimeObjects(
&custompodautoscalercomv1.CustomPodAutoscaler{
Spec: custompodautoscalercomv1.CustomPodAutoscalerSpec{
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Template: custompodautoscalercomv1.PodTemplateSpec{
Spec: custompodautoscalercomv1.PodSpec{
Containers: []corev1.Container{
{
Name: "test container",
Expand Down Expand Up @@ -499,8 +499,8 @@ func TestReconcile(t *testing.T) {
Namespace: "test-namespace",
},
Spec: custompodautoscalercomv1.CustomPodAutoscalerSpec{
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Template: custompodautoscalercomv1.PodTemplateSpec{
Spec: custompodautoscalercomv1.PodSpec{
Containers: []corev1.Container{
{
Name: "test container",
Expand Down Expand Up @@ -597,15 +597,15 @@ func TestReconcile(t *testing.T) {
Namespace: "test-namespace",
},
Spec: custompodautoscalercomv1.CustomPodAutoscalerSpec{
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Template: custompodautoscalercomv1.PodTemplateSpec{
Spec: custompodautoscalercomv1.PodSpec{
Containers: []corev1.Container{
{
Name: "test container",
},
},
},
ObjectMeta: metav1.ObjectMeta{
ObjectMeta: custompodautoscalercomv1.PodMeta{
Labels: map[string]string{
"test-label": "test",
},
Expand Down Expand Up @@ -674,8 +674,8 @@ func TestReconcile(t *testing.T) {
Namespace: "test-namespace",
},
Spec: custompodautoscalercomv1.CustomPodAutoscalerSpec{
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Template: custompodautoscalercomv1.PodTemplateSpec{
Spec: custompodautoscalercomv1.PodSpec{
Containers: []corev1.Container{
{
Name: "test container",
Expand Down Expand Up @@ -752,8 +752,8 @@ func TestReconcile(t *testing.T) {
}()).WithRuntimeObjects(
&custompodautoscalercomv1.CustomPodAutoscaler{
Spec: custompodautoscalercomv1.CustomPodAutoscalerSpec{
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Template: custompodautoscalercomv1.PodTemplateSpec{
Spec: custompodautoscalercomv1.PodSpec{
Containers: []corev1.Container{
{
Name: "test container",
Expand Down

0 comments on commit 1efee1a

Please sign in to comment.