Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mssql and fix olddbapi issue #777

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ require (
kmodules.xyz/client-go v0.30.13
kmodules.xyz/custom-resources v0.30.0
kmodules.xyz/monitoring-agent-api v0.29.0
kubedb.dev/apimachinery v0.47.0
kubedb.dev/db-client-go v0.2.0
kubedb.dev/apimachinery v0.47.1-0.20240924060721-639cafff01a9
kubedb.dev/db-client-go v0.2.1-0.20240920141523-e11cb0a2303e
sigs.k8s.io/controller-runtime v0.18.4
sigs.k8s.io/yaml v1.4.0
stash.appscode.dev/apimachinery v0.34.0
stash.appscode.dev/apimachinery v0.35.0
)

require (
Expand Down Expand Up @@ -145,7 +145,7 @@ require (
kmodules.xyz/resource-metadata v0.18.12 // indirect
kubeops.dev/petset v0.0.6 // indirect
kubeops.dev/sidekick v0.0.7 // indirect
kubestash.dev/apimachinery v0.11.0 // indirect
kubestash.dev/apimachinery v0.12.0 // indirect
sigs.k8s.io/gateway-api v1.1.0 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -725,16 +725,16 @@ kmodules.xyz/prober v0.29.0 h1:Ex7m4F9rH7uWNNJlLgP63ROOM+nUATJkC2L5OQ7nwMg=
kmodules.xyz/prober v0.29.0/go.mod h1:UtK+HKyI1lFLEKX+HFLyOCVju6TO93zv3kwGpzqmKOo=
kmodules.xyz/resource-metadata v0.18.12 h1:wHRYsvUXrX/620K0xXZlxnXJunZtHMuJbqDFZxSUs5E=
kmodules.xyz/resource-metadata v0.18.12/go.mod h1:VvUjfIzmM08SZ9ssZKhduzSrggKjY93ES2Bk+/m04hs=
kubedb.dev/apimachinery v0.47.0 h1:QhcjY2wJb/5L0YmfJAUiPw0VU1mMJqvILL2t8znniJo=
kubedb.dev/apimachinery v0.47.0/go.mod h1:W/uKm13rLuaz+uqZUt6piU/qA0EdLKHuN53V2DYheJI=
kubedb.dev/db-client-go v0.2.0 h1:ICzcrYs+UqIjBWX9NCFsASj5AfSc+10wjrjR5s0sBLA=
kubedb.dev/db-client-go v0.2.0/go.mod h1:GskxVRrpum5xGrKQ1WEPLmn2H2eLYyV5tMlEgxI31rk=
kubedb.dev/apimachinery v0.47.1-0.20240924060721-639cafff01a9 h1:6sR1SxmQvmF4xRABEDGapogL/14PYIS7cmKBzYMAoeI=
kubedb.dev/apimachinery v0.47.1-0.20240924060721-639cafff01a9/go.mod h1:iD6XKg9Blvfd9iYEO0N9GKiSz6r+yzEPZnfkYdESNG4=
kubedb.dev/db-client-go v0.2.1-0.20240920141523-e11cb0a2303e h1:f2smryo/iJT/75tyBOVaEj07bnwuHqRjYZpLbFIzY+c=
kubedb.dev/db-client-go v0.2.1-0.20240920141523-e11cb0a2303e/go.mod h1:+kfV/mezQaYJZJQdFfwiz6phpqGzzK0IXiZK15tk6vI=
kubeops.dev/petset v0.0.6 h1:0IbvxD9fadZfH+3iMZWzN6ZHsO0vX458JlioamwyPKQ=
kubeops.dev/petset v0.0.6/go.mod h1:A15vh0r979NsvL65DTIZKWsa/NoX9VapHBAEw1ZsdYI=
kubeops.dev/sidekick v0.0.7 h1:+rs9AXPsiHjq5pJpzmj+Cen7frPfdi5dK1A57eNh7GM=
kubeops.dev/sidekick v0.0.7/go.mod h1:bYS5Q6DksOzqzQPwiRbFRbV1uXuYmzY+0QYSqNFq4/M=
kubestash.dev/apimachinery v0.11.0 h1:RK1kSkuq/MIWDcGLxaLrApR4sSAcekmulGI+84FEcDc=
kubestash.dev/apimachinery v0.11.0/go.mod h1:iSumBmpU+PmxloNvHQkazCYnuxPqi3lbTXjXTI1hKqc=
kubestash.dev/apimachinery v0.12.0 h1:33eDk/W2n/K45iRpAj8JTFGq9JzSvJBoWAjyoKTklgQ=
kubestash.dev/apimachinery v0.12.0/go.mod h1:gtVSpHtK8LvS26+rKyLTnZvijvSSCdfG83n6GL6+Kwc=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
sigs.k8s.io/gateway-api v1.1.0 h1:DsLDXCi6jR+Xz8/xd0Z1PYl2Pn0TyaFMOPPZIj4inDM=
sigs.k8s.io/gateway-api v1.1.0/go.mod h1:ZH4lHrL2sDi0FHZ9jjneb8kKnGzFWyrTya35sWUTrRs=
Expand All @@ -748,5 +748,5 @@ sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+s
sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
stash.appscode.dev/apimachinery v0.34.0 h1:8/Vi6w5Q+eAf7M7HArhvK+gay9cHPOvzAK6QCwdzRTg=
stash.appscode.dev/apimachinery v0.34.0/go.mod h1:qAVdUDtYDYiytYqKIHon4BMs1OXBdu3wDpfEfhM18b0=
stash.appscode.dev/apimachinery v0.35.0 h1:Z+2v4vqEUi7yJeg5yCg4Kh2YDq8HtgQf/9jYYst6uW0=
stash.appscode.dev/apimachinery v0.35.0/go.mod h1:YigRBV5veSSAzN23ibQcpkChvq8HPdiU0kq8uvw/5Fo=
3 changes: 3 additions & 0 deletions pkg/cmds/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ var alertExample = templates.Examples(`
* kafka
* mariadb
* mongodb
* mssql
* mysql
* perconaxtradb
* pgpool
Expand Down Expand Up @@ -144,6 +145,7 @@ var dashboardExample = templates.Examples(`
* kafka
* mariadb
* mongodb
* mssql
* mysql
* perconaxtradb
* pgpool
Expand Down Expand Up @@ -208,6 +210,7 @@ var connectionExample = templates.Examples(`
* kafka
* mariadb
* mongodb
* mssql
* mysql
* perconaxtradb
* pgpool
Expand Down
6 changes: 6 additions & 0 deletions pkg/monitor/dashboard/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (

kapi "kubedb.dev/apimachinery/apis/kafka/v1alpha1"
dbapi "kubedb.dev/apimachinery/apis/kubedb/v1"
olddbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
"kubedb.dev/cli/pkg/monitor"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand All @@ -53,6 +55,10 @@ func getDB(f cmdutil.Factory, resource, ns, name string) (*unstructured.Unstruct
}

gvk := dbapi.SchemeGroupVersion
if monitor.IsOldAPI(resource) {
gvk = olddbapi.SchemeGroupVersion
}

dbRes := schema.GroupVersionResource{Group: gvk.Group, Version: gvk.Version, Resource: resource}
return dc.Resource(dbRes).Namespace(ns).Get(context.TODO(), name, metav1.GetOptions{})
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/monitor/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func ConvertedResourceToPlural(resource string) string {
res = dbapi.ResourcePluralMariaDB
case dbapi.ResourceCodeMongoDB, dbapi.ResourcePluralMongoDB, dbapi.ResourceSingularMongoDB:
res = dbapi.ResourcePluralMongoDB
case olddbapi.ResourceCodeMSSQLServer, olddbapi.ResourcePluralMSSQLServer, olddbapi.ResourceSingularMSSQLServer:
res = olddbapi.ResourcePluralMSSQLServer
case dbapi.ResourceCodeMySQL, dbapi.ResourcePluralMySQL, dbapi.ResourceSingularMySQL:
res = dbapi.ResourcePluralMySQL
case dbapi.ResourceCodePerconaXtraDB, dbapi.ResourcePluralPerconaXtraDB, dbapi.ResourceSingularPerconaXtraDB:
Expand Down Expand Up @@ -83,6 +85,8 @@ func ConvertedResourceToSingular(resource string) string {
res = dbapi.ResourceSingularMariaDB
case dbapi.ResourceCodeMongoDB, dbapi.ResourcePluralMongoDB, dbapi.ResourceSingularMongoDB:
res = dbapi.ResourceSingularMongoDB
case olddbapi.ResourceCodeMSSQLServer, olddbapi.ResourcePluralMSSQLServer, olddbapi.ResourceSingularMSSQLServer:
res = olddbapi.ResourceSingularMSSQLServer
case dbapi.ResourceCodeMySQL, dbapi.ResourcePluralMySQL, dbapi.ResourceSingularMySQL:
res = dbapi.ResourceSingularMySQL
case dbapi.ResourceCodePerconaXtraDB, dbapi.ResourcePluralPerconaXtraDB, dbapi.ResourceSingularPerconaXtraDB:
Expand All @@ -108,3 +112,17 @@ func ConvertedResourceToSingular(resource string) string {
}
return res
}

func IsOldAPI(resource string) bool {
oldDBApi := []string{
olddbapi.ResourcePluralDruid, olddbapi.ResourcePluralSinglestore, olddbapi.ResourcePluralRabbitmq, olddbapi.ResourcePluralPgpool,
olddbapi.ResourcePluralMSSQLServer, olddbapi.ResourcePluralSolr, olddbapi.ResourcePluralCassandra, olddbapi.ResourcePluralClickHouse,
olddbapi.ResourcePluralFerretDB, olddbapi.ResourcePluralZooKeeper,
}
for _, api := range oldDBApi {
if resource == api {
return true
}
}
return false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
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/autoscaling"
"kubedb.dev/apimachinery/crds"

"kmodules.xyz/client-go/apiextensions"
)

func (r CassandraAutoscaler) CustomResourceDefinition() *apiextensions.CustomResourceDefinition {
return crds.MustCustomResourceDefinition(SchemeGroupVersion.WithResource(ResourcePluralCassandraAutoscaler))
}

var _ apis.ResourceInfo = &CassandraAutoscaler{}

func (r CassandraAutoscaler) ResourceFQN() string {
return fmt.Sprintf("%s.%s", ResourcePluralCassandraAutoscaler, autoscaling.GroupName)
}

func (r CassandraAutoscaler) ResourceShortCode() string {
return ResourceCodeCassandraAutoscaler
}

func (r CassandraAutoscaler) ResourceKind() string {
return ResourceKindCassandraAutoscaler
}

func (r CassandraAutoscaler) ResourceSingular() string {
return ResourceSingularCassandraAutoscaler
}

func (r CassandraAutoscaler) ResourcePlural() string {
return ResourcePluralCassandraAutoscaler
}

func (r CassandraAutoscaler) ValidateSpecs() error {
return nil
}

var _ StatusAccessor = &CassandraAutoscaler{}

func (r *CassandraAutoscaler) GetStatus() AutoscalerStatus {
return r.Status
}

func (r *CassandraAutoscaler) SetStatus(s AutoscalerStatus) {
r.Status = s
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
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 (
opsapi "kubedb.dev/apimachinery/apis/ops/v1alpha1"

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

const (
ResourceCodeCassandraAutoscaler = "casscaler"
ResourceKindCassandraAutoscaler = "CassandraAutoscaler"
ResourceSingularCassandraAutoscaler = "cassandraautoscaler"
ResourcePluralCassandraAutoscaler = "cassandraautoscalers"
)

// CassandraAutoscaler is the configuration for a cassandra database
// autoscaler, which automatically manages pod resources based on historical and
// real time resource utilization.

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

// +kubebuilder:object:root=true
// +kubebuilder:resource:path=cassandraautoscalers,singular=cassandraautoscaler,shortName=casscaler,categories={autoscaler,kubedb,appscode}
// +kubebuilder:subresource:status
type CassandraAutoscaler struct {
metav1.TypeMeta `json:",inline"`
// Standard object metadata. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`

// Specification of the behavior of the autoscaler.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status.
Spec CassandraAutoscalerSpec `json:"spec"`

// Current information about the autoscaler.
// +optional
Status AutoscalerStatus `json:"status,omitempty"`
}

// CassandraAutoscalerSpec is the specification of the behavior of the autoscaler.
type CassandraAutoscalerSpec struct {
DatabaseRef *core.LocalObjectReference `json:"databaseRef"`

// This field will be used to control the behaviour of ops-manager
OpsRequestOptions *CassandraOpsRequestOptions `json:"opsRequestOptions,omitempty"`

Compute *CassandraComputeAutoscalerSpec `json:"compute,omitempty"`
Storage *CassandraStorageAutoscalerSpec `json:"storage,omitempty"`
}

type CassandraComputeAutoscalerSpec struct {
// +optional
NodeTopology *NodeTopology `json:"nodeTopology,omitempty"`

Cassandra *ComputeAutoscalerSpec `json:"cassandra,omitempty"`
}

type CassandraStorageAutoscalerSpec struct {
Cassandra *StorageAutoscalerSpec `json:"cassandra,omitempty"`
}

type CassandraOpsRequestOptions struct {
// 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 opsapi.ApplyOption `json:"apply,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// CassandraAutoscalerList is a list of CassandraAutoscaler objects.
type CassandraAutoscalerList struct {
metav1.TypeMeta `json:",inline"`
// metadata is the standard list metadata.
// +optional
metav1.ListMeta `json:"metadata"`

// items is the list of cassandra database autoscaler objects.
Items []CassandraAutoscaler `json:"items"`
}
Loading
Loading