diff --git a/api/v1alpha1/hivemetastore_types.go b/api/v1alpha1/hivemetastore_types.go index 3c49fe5..180d541 100644 --- a/api/v1alpha1/hivemetastore_types.go +++ b/api/v1alpha1/hivemetastore_types.go @@ -151,7 +151,7 @@ type RoleSpec struct { RoleGroups map[string]*RoleGroupSpec `json:"roleGroups"` // +kubebuilder:validation:Optional - PodDisruptionBudget *commonsv1alpha1.PodDisruptionBudgetSpec `json:"podDisruptionBudget,omitempty"` + RoleConfig *commonsv1alpha1.RoleConfigSpec `json:"roleConfig,omitempty"` // +kubebuilder:validation:Optional CliOverrides []string `json:"cliOverrides,omitempty"` diff --git a/api/v1alpha1/resources.go b/api/v1alpha1/resources.go deleted file mode 100644 index 01c2e66..0000000 --- a/api/v1alpha1/resources.go +++ /dev/null @@ -1,42 +0,0 @@ -package v1alpha1 - -import ( - "k8s.io/apimachinery/pkg/api/resource" -) - -type ResourcesSpec struct { - // +kubebuilder:validation:Optional - CPU *CPUResource `json:"cpu,omitempty"` - - // +kubebuilder:validation:Optional - Memory *MemoryResource `json:"memory,omitempty"` - - // +kubebuilder:validation:Optional - Storage *StorageResource `json:"storage,omitempty"` -} - -type StorageResourceSpec struct { - Data *StorageResource `json:"data"` -} - -type CPUResource struct { - // +kubebuilder:validation:Optional - Max *resource.Quantity `json:"max,omitempty"` - - // +kubebuilder:validation:Optional - Min *resource.Quantity `json:"min,omitempty"` -} - -type MemoryResource struct { - // +kubebuilder:validation:Optional - Limit *resource.Quantity `json:"limit,omitempty"` -} - -type StorageResource struct { - // +kubebuilder:validation:Optional - // +kubebuilder:default="10Gi" - Capacity resource.Quantity `json:"capacity,omitempty"` - - // +kubebuilder:validation:Optional - StorageClass string `json:"storageClass,omitempty"` -} diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 67528dc..eed32e0 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -53,31 +53,6 @@ func (in *AuthenticationSpec) DeepCopy() *AuthenticationSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *CPUResource) DeepCopyInto(out *CPUResource) { - *out = *in - if in.Max != nil { - in, out := &in.Max, &out.Max - x := (*in).DeepCopy() - *out = &x - } - if in.Min != nil { - in, out := &in.Min, &out.Min - x := (*in).DeepCopy() - *out = &x - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CPUResource. -func (in *CPUResource) DeepCopy() *CPUResource { - if in == nil { - return nil - } - out := new(CPUResource) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ClusterConfigSpec) DeepCopyInto(out *ClusterConfigSpec) { *out = *in @@ -351,56 +326,6 @@ func (in *LoggingSpec) DeepCopy() *LoggingSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MemoryResource) DeepCopyInto(out *MemoryResource) { - *out = *in - if in.Limit != nil { - in, out := &in.Limit, &out.Limit - x := (*in).DeepCopy() - *out = &x - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemoryResource. -func (in *MemoryResource) DeepCopy() *MemoryResource { - if in == nil { - return nil - } - out := new(MemoryResource) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ResourcesSpec) DeepCopyInto(out *ResourcesSpec) { - *out = *in - if in.CPU != nil { - in, out := &in.CPU, &out.CPU - *out = new(CPUResource) - (*in).DeepCopyInto(*out) - } - if in.Memory != nil { - in, out := &in.Memory, &out.Memory - *out = new(MemoryResource) - (*in).DeepCopyInto(*out) - } - if in.Storage != nil { - in, out := &in.Storage, &out.Storage - *out = new(StorageResource) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourcesSpec. -func (in *ResourcesSpec) DeepCopy() *ResourcesSpec { - if in == nil { - return nil - } - out := new(ResourcesSpec) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RoleGroupSpec) DeepCopyInto(out *RoleGroupSpec) { *out = *in @@ -464,9 +389,9 @@ func (in *RoleSpec) DeepCopyInto(out *RoleSpec) { (*out)[key] = outVal } } - if in.PodDisruptionBudget != nil { - in, out := &in.PodDisruptionBudget, &out.PodDisruptionBudget - *out = new(commonsv1alpha1.PodDisruptionBudgetSpec) + if in.RoleConfig != nil { + in, out := &in.RoleConfig, &out.RoleConfig + *out = new(commonsv1alpha1.RoleConfigSpec) (*in).DeepCopyInto(*out) } if in.CliOverrides != nil { @@ -520,42 +445,6 @@ func (in *S3Spec) DeepCopy() *S3Spec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *StorageResource) DeepCopyInto(out *StorageResource) { - *out = *in - out.Capacity = in.Capacity.DeepCopy() -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageResource. -func (in *StorageResource) DeepCopy() *StorageResource { - if in == nil { - return nil - } - out := new(StorageResource) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *StorageResourceSpec) DeepCopyInto(out *StorageResourceSpec) { - *out = *in - if in.Data != nil { - in, out := &in.Data, &out.Data - *out = new(StorageResource) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new StorageResourceSpec. -func (in *StorageResourceSpec) DeepCopy() *StorageResourceSpec { - if in == nil { - return nil - } - out := new(StorageResourceSpec) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TlsSpec) DeepCopyInto(out *TlsSpec) { *out = *in diff --git a/config/crd/bases/zncdata.dev_hivemetastores.yaml b/config/crd/bases/zncdata.dev_hivemetastores.yaml index 80c54fe..666339d 100644 --- a/config/crd/bases/zncdata.dev_hivemetastores.yaml +++ b/config/crd/bases/zncdata.dev_hivemetastores.yaml @@ -1308,19 +1308,22 @@ spec: additionalProperties: type: string type: object - podDisruptionBudget: - description: |- - This struct is used to configure: - - 1. If PodDisruptionBudgets are created by the operator - 2. The allowed number of Pods to be unavailable (`maxUnavailable`) + roleConfig: properties: - enabled: - default: true - type: boolean - maxUnavailable: - format: int32 - type: integer + podDisruptionBudget: + description: |- + This struct is used to configure: + + 1. If PodDisruptionBudgets are created by the operator + 2. The allowed number of Pods to be unavailable (`maxUnavailable`) + properties: + enabled: + default: true + type: boolean + maxUnavailable: + format: int32 + type: integer + type: object type: object roleGroups: additionalProperties: diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index cefff89..3da6b92 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -37,6 +37,18 @@ rules: - patch - update - watch +- apiGroups: + - policy + resources: + - poddisruptionbudgets + verbs: + - create + - delete + - get + - list + - patch + - update + - watch - apiGroups: - s3.zncdata.dev resources: diff --git a/internal/controller/metastore_controller.go b/internal/controller/metastore_controller.go index 5395067..74d0b3d 100644 --- a/internal/controller/metastore_controller.go +++ b/internal/controller/metastore_controller.go @@ -48,6 +48,7 @@ type HiveMetastoreReconciler struct { // +kubebuilder:rbac:groups=core,resources=pods,verbs=get;list;watch // +kubebuilder:rbac:groups=s3.zncdata.dev,resources=s3connections,verbs=get;list;watch // +kubebuilder:rbac:groups=s3.zncdata.dev,resources=s3buckets,verbs=get;list;watch +// +kubebuilder:rbac:groups=policy,resources=poddisruptionbudgets,verbs=get;list;watch;create;update;patch;delete func (r *HiveMetastoreReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { log.Info("Reconciling instance") diff --git a/test/e2e/pdb/chainsaw-test.yaml b/test/e2e/pdb/chainsaw-test.yaml new file mode 100644 index 0000000..6a3c7e7 --- /dev/null +++ b/test/e2e/pdb/chainsaw-test.yaml @@ -0,0 +1,11 @@ +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + name: pdb +spec: + steps: + - try: + - apply: + file: hive.yaml + - assert: + file: hive-assert.yaml diff --git a/test/e2e/pdb/hive-assert.yaml b/test/e2e/pdb/hive-assert.yaml new file mode 100644 index 0000000..7302180 --- /dev/null +++ b/test/e2e/pdb/hive-assert.yaml @@ -0,0 +1,26 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: hive-vector-metastore-default +status: + availableReplicas: 1 + readyReplicas: 1 + replicas: 1 +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: hive-vector-metastore-default +--- +apiVersion: v1 +kind: Service +metadata: + name: hive-vector-metastore-default +--- +# pdb +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: hive-vector-metastore +spec: + maxUnavailable: 2 diff --git a/test/e2e/pdb/hive.yaml b/test/e2e/pdb/hive.yaml new file mode 100644 index 0000000..f2d8d56 --- /dev/null +++ b/test/e2e/pdb/hive.yaml @@ -0,0 +1,29 @@ +--- +apiVersion: v1 +kind: Secret +metadata: + name: hive +type: Opaque +stringData: + username: hive + password: hive +--- +apiVersion: zncdata.dev/v1alpha1 +kind: HiveMetastore +metadata: + name: hive-vector +spec: + clusterConfig: + database: + databaseType: derby + connectionString: jdbc:derby:;databaseName=metastore_db;create=true + credentialsSecret: hive + metastore: + roleConfig: + podDisruptionBudget: + maxUnavailable: 2 + roleGroups: + default: + config: + warehouseDir: /kubedoop/warehouse + replicas: 1