Skip to content

Commit

Permalink
feat: Move policy/v1beta1 to policy/v1 for K8s 1.25+ compatability
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Witkowski authored and jwitko committed Feb 21, 2023
1 parent c64e9c0 commit 63e1ef6
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ NAMESPACE_MINIO_OPERATOR ?= "minio-operator"
NAMESPACE_DRUID ?= "druid"

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.24.2
ENVTEST_K8S_VERSION = 1.25.0

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
- ```Druid``` CR belongs to api Group ```druid.apache.org``` and version ```v1alpha1```

### Notifications
- Users may experience HPA issues with druid-operator with release 0.0.5, as described in the [issue]( https://github.com/druid-io/druid-operator/issues/160).
- Users may experience HPA issues with druid-operator with release 0.0.5, as described in the [issue]( https://github.com/druid-io/druid-operator/issues/160).
- The latest release 0.0.6 has fixes for the above issue.
- The operator has moved from HPA apiVersion autoscaling/v2beta1 to autoscaling/v2beta2 API users will need to update there HPA Specs according v2beta2 api in order to work with the latest druid-operator release.
- Users may experience pvc deletion [issue](https://github.com/druid-io/druid-operator/issues/186) in release 0.0.6, this issue has been fixed in patch release 0.0.6.1.
- druid-operator has moved Ingress apiVersion networking/v1beta1 to networking/v1. Users will need to update there Ingress Spec in the druid CR according networking/v1 syntax. In case users are using schema validated CRD, the CRD will also be needed to be updated.
- druid-operator has moved PodDisruptionBudget apiVersion policy/v1beta1 to policy/v1. Users will need to update there Kubernetes versions to 1.21+ to use druid-operator-0.0.10+.

### Note
Apache®, [Apache Druid, Druid®](https://druid.apache.org/) are either registered trademarks or trademarks of the Apache Software Foundation in the United States and/or other countries. This project, druid-operator, is not an Apache Software Foundation project.
4 changes: 2 additions & 2 deletions apis/druid/v1alpha1/druid_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
autoscalev2beta2 "k8s.io/api/autoscaling/v2beta2"
v1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
"k8s.io/api/policy/v1beta1"
policyv1 "k8s.io/api/policy/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -208,7 +208,7 @@ type DruidNodeSpec struct {
PodLabels map[string]string `json:"podLabels,omitempty"`

// Optional
PodDisruptionBudgetSpec *v1beta1.PodDisruptionBudgetSpec `json:"podDisruptionBudgetSpec,omitempty"`
PodDisruptionBudgetSpec *policyv1.PodDisruptionBudgetSpec `json:"podDisruptionBudgetSpec,omitempty"`

// Required
RuntimeProperties string `json:"runtime.properties"`
Expand Down
4 changes: 2 additions & 2 deletions apis/druid/v1alpha1/zz_generated.deepcopy.go

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

190 changes: 186 additions & 4 deletions controllers/druid/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/druid-io/druid-operator/apis/druid/v1alpha1"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
policyv1 "k8s.io/api/policy/v1"
"k8s.io/api/policy/v1beta1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -346,7 +347,7 @@ func deployDruidCluster(sdk client.Client, m *v1alpha1.Druid, emitEvents EventEm
updatedStatus.PodDisruptionBudgets = deleteUnusedResources(sdk, m, podDisruptionBudgetNames, ls,
func() objectList { return &v1beta1.PodDisruptionBudgetList{} },
func(listObj runtime.Object) []object {
items := listObj.(*v1beta1.PodDisruptionBudgetList).Items
items := listObj.(*policyv1.PodDisruptionBudgetList).Items
result := make([]object, len(items))
for i := 0; i < len(items); i++ {
result[i] = &items[i]
Expand Down Expand Up @@ -1366,13 +1367,13 @@ func updateDefaultPortInProbe(probe *v1.Probe, defaultPort int32) *v1.Probe {
return probe
}

func makePodDisruptionBudget(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid, ls map[string]string, nodeSpecUniqueStr string) (*v1beta1.PodDisruptionBudget, error) {
func makePodDisruptionBudget(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid, ls map[string]string, nodeSpecUniqueStr string) (*policyv1.PodDisruptionBudget, error) {
pdbSpec := *nodeSpec.PodDisruptionBudgetSpec
pdbSpec.Selector = &metav1.LabelSelector{MatchLabels: ls}

pdb := &v1beta1.PodDisruptionBudget{
pdb := &policyv1.PodDisruptionBudget{
TypeMeta: metav1.TypeMeta{
APIVersion: "policy/v1beta1",
APIVersion: "policy/v1",
Kind: "PodDisruptionBudget",
},

Expand Down Expand Up @@ -1502,6 +1503,187 @@ func asOwner(m *v1alpha1.Druid) metav1.OwnerReference {
}
}

// podList returns a v1.PodList object
func makePodList() *v1.PodList {
return &v1.PodList{
TypeMeta: metav1.TypeMeta{
Kind: "Pod",
APIVersion: "v1",
},
}
}

func makeDruidEmptyObj() *v1alpha1.Druid {
return &v1alpha1.Druid{
TypeMeta: metav1.TypeMeta{
Kind: "Druid",
APIVersion: "v1alpha1",
},
}
}

func makeStatefulSetListEmptyObj() *appsv1.StatefulSetList {
return &appsv1.StatefulSetList{
TypeMeta: metav1.TypeMeta{
Kind: "StatefulSet",
APIVersion: "apps/v1",
},
}
}

func makeDeloymentListEmptyObj() *appsv1.DeploymentList {
return &appsv1.DeploymentList{
TypeMeta: metav1.TypeMeta{
Kind: "Deployment",
APIVersion: "apps/v1",
},
}
}

func makePodDisruptionBudgetListEmptyObj() *policyv1.PodDisruptionBudgetList {
return &policyv1.PodDisruptionBudgetList{
TypeMeta: metav1.TypeMeta{
APIVersion: "policy/v1",
Kind: "PodDisruptionBudget",
},
}
}

func makeHorizontalPodAutoscalerListEmptyObj() *autoscalev2beta2.HorizontalPodAutoscalerList {
return &autoscalev2beta2.HorizontalPodAutoscalerList{
TypeMeta: metav1.TypeMeta{
APIVersion: "autoscaling/v2beta1",
Kind: "HorizontalPodAutoscaler",
},
}
}

func makeIngressListEmptyObj() *networkingv1.IngressList {
return &networkingv1.IngressList{
TypeMeta: metav1.TypeMeta{
APIVersion: "networking.k8s.io/v1",
Kind: "Ingress",
},
}
}

func makeConfigMapListEmptyObj() *v1.ConfigMapList {
return &v1.ConfigMapList{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
},
}
}

func makeServiceListEmptyObj() *v1.ServiceList {
return &v1.ServiceList{
TypeMeta: metav1.TypeMeta{
Kind: "Service",
APIVersion: "v1",
},
}
}

func makePodEmptyObj() *v1.Pod {
return &v1.Pod{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Pod",
},
}
}

func makeStatefulSetEmptyObj() *appsv1.StatefulSet {
return &appsv1.StatefulSet{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Kind: "StatefulSet",
},
}
}

func makeDeploymentEmptyObj() *appsv1.Deployment {
return &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Kind: "Deployment",
},
}
}

func makePodDisruptionBudgetEmptyObj() *policyv1.PodDisruptionBudget {
return &policyv1.PodDisruptionBudget{
TypeMeta: metav1.TypeMeta{
APIVersion: "policy/v1",
Kind: "PodDisruptionBudget",
},
}
}

func makeHorizontalPodAutoscalerEmptyObj() *autoscalev2beta2.HorizontalPodAutoscaler {
return &autoscalev2beta2.HorizontalPodAutoscaler{
TypeMeta: metav1.TypeMeta{
APIVersion: "autoscaling/v2beta1",
Kind: "HorizontalPodAutoscaler",
},
}
}

func makePersistentVolumeClaimEmptyObj() *v1.PersistentVolumeClaim {
return &v1.PersistentVolumeClaim{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "PersistentVolumeClaim",
},
}
}

func makePersistentVolumeClaimListEmptyObj() *v1.PersistentVolumeClaimList {
return &v1.PersistentVolumeClaimList{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "PersistentVolumeClaim",
},
}
}

func makeIngressEmptyObj() *networkingv1.Ingress {
return &networkingv1.Ingress{
TypeMeta: metav1.TypeMeta{
APIVersion: "networking.k8s.io/v1",
Kind: "Ingress",
},
}
}

func makeServiceEmptyObj() *v1.Service {
return &v1.Service{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Service",
},
}
}

func makeStorageClassEmptyObj() *storage.StorageClass {
return &storage.StorageClass{
TypeMeta: metav1.TypeMeta{
APIVersion: "storage.k8s.io/v1",
Kind: "StorageClass",
},
}
}

func makeConfigMapEmptyObj() *v1.ConfigMap {
return &v1.ConfigMap{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "ConfigMap",
},
}
}

// getPodNames returns the pod names of the array of pods passed in
func getPodNames(pods []object) []string {
var podNames []string
Expand Down
4 changes: 2 additions & 2 deletions controllers/druid/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/ghodss/yaml"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/api/policy/v1beta1"
policyv1 "k8s.io/api/policy/v1"
)

func TestMakeStatefulSetForBroker(t *testing.T) {
Expand Down Expand Up @@ -67,7 +67,7 @@ func TestMakePodDisruptionBudgetForBroker(t *testing.T) {
actual, _ := makePodDisruptionBudget(&nodeSpec, clusterSpec, makeLabelsForNodeSpec(&nodeSpec, clusterSpec, clusterSpec.Name, nodeSpecUniqueStr), nodeSpecUniqueStr)
addHashToObject(actual)

expected := new(v1beta1.PodDisruptionBudget)
expected := new(policyv1.PodDisruptionBudget)
readAndUnmarshallResource("testdata/broker-pod-disruption-budget.yaml", &expected, t)

assertEquals(expected, actual, t)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: policy/v1beta1
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
labels:
Expand Down

0 comments on commit 63e1ef6

Please sign in to comment.