Skip to content

Commit

Permalink
Add Druid ops-request API
Browse files Browse the repository at this point in the history
Signed-off-by: Tapajit Chandra Paul <[email protected]>
  • Loading branch information
tapojit047 committed May 31, 2024
1 parent a0277a7 commit 5009ea9
Show file tree
Hide file tree
Showing 18 changed files with 1,723 additions and 37 deletions.
6 changes: 6 additions & 0 deletions apis/ops/v1alpha1/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ const (
HorizontalScaleSentinelDown = "HorizontalScaleSentinelDown"
)

// Druid Constants
const (
UpdateMiddleManagersNodePVCs = "UpdateMiddleManagersNodePVCs"
UpdateHistoricalsNodePVCs = "UpdateHistoricalsNodePVCs"
)

// SingleStore Constants
const (
UpdateAggregatorNodePVCs = "UpdateAggregatorNodePVCs"
Expand Down
76 changes: 76 additions & 0 deletions apis/ops/v1alpha1/druid_ops_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Copyright AppsCode Inc. and Contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"fmt"

"kubedb.dev/apimachinery/apis"
"kubedb.dev/apimachinery/apis/ops"
"kubedb.dev/apimachinery/crds"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"kmodules.xyz/client-go/apiextensions"
)

func (d *DruidOpsRequest) CustomResourceDefinition() *apiextensions.CustomResourceDefinition {
return crds.MustCustomResourceDefinition(SchemeGroupVersion.WithResource(ResourcePluralDruidOpsRequest))
}

var _ apis.ResourceInfo = &DruidOpsRequest{}

func (d *DruidOpsRequest) ResourceFQN() string {
return fmt.Sprintf("%s.%s", ResourcePluralDruidOpsRequest, ops.GroupName)
}

func (d *DruidOpsRequest) ResourceShortCode() string {
return ResourceCodeDruidOpsRequest
}

func (d *DruidOpsRequest) ResourceKind() string {
return ResourceKindDruidOpsRequest
}

func (d *DruidOpsRequest) ResourceSingular() string {
return ResourceSingularDruidOpsRequest
}

func (d *DruidOpsRequest) ResourcePlural() string {
return ResourcePluralDruidOpsRequest
}

var _ Accessor = &DruidOpsRequest{}

func (d *DruidOpsRequest) GetObjectMeta() metav1.ObjectMeta {
return d.ObjectMeta
}

func (d *DruidOpsRequest) GetDBRefName() string {
return d.Spec.DatabaseRef.Name
}

func (d *DruidOpsRequest) GetRequestType() any {
return d.Spec.Type
}

func (d *DruidOpsRequest) GetStatus() OpsRequestStatus {
return d.Status
}

func (d *DruidOpsRequest) SetStatus(s OpsRequestStatus) {
d.Status = s
}
102 changes: 102 additions & 0 deletions apis/ops/v1alpha1/druid_ops_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
Copyright AppsCode Inc. and Contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

//go:generate go-enum --mustparse --names --values
package v1alpha1

import (
core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
ResourceCodeDruidOpsRequest = "drops"
ResourceKindDruidOpsRequest = "DruidOpsRequest"
ResourceSingularDruidOpsRequest = "druidopsrequest"
ResourcePluralDruidOpsRequest = "druidopsrequests"
)

// DruidDBOpsRequest defines a Druid DBA operation.

// +genclient
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// +kubebuilder:object:root=true
// +kubebuilder:resource:path=druidopsrequests,singular=druidopsrequest,shortName=drops,categories={datastore,kubedb,appscode}
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Type",type="string",JSONPath=".spec.type"
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.phase"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
type DruidOpsRequest struct {
metav1.TypeMeta `json:",inline,omitempty"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec DruidOpsRequestSpec `json:"spec,omitempty"`
Status OpsRequestStatus `json:"status,omitempty"`
}

// DruidOpsRequestSpec is the spec for DruidOpsRequest
type DruidOpsRequestSpec struct {
// Specifies the Druid reference
DatabaseRef core.LocalObjectReference `json:"databaseRef"`
// Specifies the ops request type: UpdateVersion, HorizontalScaling, VerticalScaling etc.
Type DruidOpsRequestType `json:"type"`
// Specifies information necessary for vertical scaling
VerticalScaling *DruidVerticalScalingSpec `json:"verticalScaling,omitempty"`
// Specifies information necessary for volume expansion
VolumeExpansion *DruidVolumeExpansionSpec `json:"volumeExpansion,omitempty"`
// Specifies information necessary for restarting database
Restart *RestartSpec `json:"restart,omitempty"`
// Timeout for each step of the ops request in second. If a step doesn't finish within the specified timeout, the ops request will result in failure.
Timeout *metav1.Duration `json:"timeout,omitempty"`
// ApplyOption is to control the execution of OpsRequest depending on the database state.
// +kubebuilder:default="IfReady"
Apply ApplyOption `json:"apply,omitempty"`
}

// +kubebuilder:validation:Enum=VerticalScaling;VolumeExpansion;Restart
// ENUM(VerticalScaling, VolumeExpansion, Restart)
type DruidOpsRequestType string

// DruidVerticalScalingSpec contains the vertical scaling information of a Druid cluster
type DruidVerticalScalingSpec struct {
Coordinators *PodResources `json:"coordinators,omitempty"`
Overlords *PodResources `json:"overlords,omitempty"`
MiddleManagers *PodResources `json:"middleManagers,omitempty"`
Historicals *PodResources `json:"historicals,omitempty"`
Brokers *PodResources `json:"brokers,omitempty"`
Routers *PodResources `json:"routers,omitempty"`
}

// DruidVolumeExpansionSpec is the spec for Druid volume expansion
type DruidVolumeExpansionSpec struct {
Mode VolumeExpansionMode `json:"mode"`
// volume specification for middleManagers nodes
MiddleManagers *resource.Quantity `json:"middleManagers,omitempty"`
// volume specification for historicals nodes
Historicals *resource.Quantity `json:"historicals,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// DruidOpsRequestList is a list of DruidOpsRequests
type DruidOpsRequestList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
// Items is a list of DruidOpsRequest CRD objects
Items []DruidOpsRequest `json:"items,omitempty"`
}
80 changes: 80 additions & 0 deletions apis/ops/v1alpha1/druid_ops_types_enum.go

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

Loading

0 comments on commit 5009ea9

Please sign in to comment.