Skip to content

Commit

Permalink
Change dashboard api group to elasticsearch
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Jan 17, 2024
1 parent 3b88c8f commit 9ee3a0f
Show file tree
Hide file tree
Showing 47 changed files with 39,756 additions and 2,723 deletions.
2 changes: 1 addition & 1 deletion elasticsearch/kubedb_client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"time"

catalog "kubedb.dev/apimachinery/apis/catalog/v1alpha1"
"kubedb.dev/apimachinery/apis/dashboard/v1alpha1"
"kubedb.dev/apimachinery/apis/elasticsearch/v1alpha1"
api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"

"github.com/Masterminds/semver/v3"
Expand Down
4 changes: 2 additions & 2 deletions elasticsearchdashboard/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ limitations under the License.
package elasticsearchdashboard

import (
dapi "kubedb.dev/apimachinery/apis/dashboard/v1alpha1"
esapi "kubedb.dev/apimachinery/apis/elasticsearch/v1alpha1"
)

type EDClient interface {
GetHealthStatus() (*Health, error)
GetStateFromHealthResponse(health *Health) (dapi.DashboardServerState, error)
GetStateFromHealthResponse(health *Health) (esapi.DashboardServerState, error)
}
4 changes: 2 additions & 2 deletions elasticsearchdashboard/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"net/http"

catalog "kubedb.dev/apimachinery/apis/catalog/v1alpha1"
dapi "kubedb.dev/apimachinery/apis/dashboard/v1alpha1"
esapi "kubedb.dev/apimachinery/apis/elasticsearch/v1alpha1"
api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"

core "k8s.io/api/core/v1"
Expand All @@ -35,7 +35,7 @@ type Client struct {

type ClientOptions struct {
KClient client.Client
Dashboard *dapi.ElasticsearchDashboard
Dashboard *esapi.ElasticsearchDashboard
ESVersion *catalog.ElasticsearchVersion
DB *api.Elasticsearch
Ctx context.Context
Expand Down
8 changes: 4 additions & 4 deletions elasticsearchdashboard/ed_client_v7.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"io"
"strings"

dapi "kubedb.dev/apimachinery/apis/dashboard/v1alpha1"
esapi "kubedb.dev/apimachinery/apis/elasticsearch/v1alpha1"

"github.com/go-resty/resty/v2"
"github.com/pkg/errors"
Expand Down Expand Up @@ -57,7 +57,7 @@ func (h *EDClientV7) GetHealthStatus() (*Health, error) {

// GetStateFromHealthResponse parse health response in json from server and
// return overall status of the server
func (h *EDClientV7) GetStateFromHealthResponse(health *Health) (dapi.DashboardServerState, error) {
func (h *EDClientV7) GetStateFromHealthResponse(health *Health) (esapi.DashboardServerState, error) {
resStatus := health.ConnectionResponse

defer func(Body io.ReadCloser) {
Expand Down Expand Up @@ -93,7 +93,7 @@ func (h *EDClientV7) GetStateFromHealthResponse(health *Health) (dapi.DashboardS
if statuses, ok := responseBody.Status["statuses"].([]interface{}); ok {
for _, sts := range statuses {
if curr, ok := sts.(map[string]interface{}); ok {
if curr["state"].(string) != string(dapi.StateGreen) {
if curr["state"].(string) != string(esapi.StateGreen) {
health.StateFailedReason[curr["id"].(string)] = strings.Join([]string{curr["state"].(string), curr["message"].(string)}, ",")
}
} else {
Expand All @@ -104,5 +104,5 @@ func (h *EDClientV7) GetStateFromHealthResponse(health *Health) (dapi.DashboardS
return "", errors.New("Failed to convert statuses to []interface{}")
}

return dapi.DashboardServerState(health.OverallState), nil
return esapi.DashboardServerState(health.OverallState), nil
}
8 changes: 4 additions & 4 deletions elasticsearchdashboard/ed_client_v8.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"io"
"strings"

dapi "kubedb.dev/apimachinery/apis/dashboard/v1alpha1"
esapi "kubedb.dev/apimachinery/apis/elasticsearch/v1alpha1"

"github.com/go-resty/resty/v2"
"github.com/pkg/errors"
Expand Down Expand Up @@ -57,7 +57,7 @@ func (h *EDClientV8) GetHealthStatus() (*Health, error) {

// GetStateFromHealthResponse parse health response in json from server and
// return overall status of the server
func (h *EDClientV8) GetStateFromHealthResponse(health *Health) (dapi.DashboardServerState, error) {
func (h *EDClientV8) GetStateFromHealthResponse(health *Health) (esapi.DashboardServerState, error) {
resStatus := health.ConnectionResponse

defer func(Body io.ReadCloser) {
Expand Down Expand Up @@ -91,7 +91,7 @@ func (h *EDClientV8) GetStateFromHealthResponse(health *Health) (dapi.DashboardS
if pluginsStatus, ok := responseBody.Status["plugins"].(map[string]interface{}); ok {
for plugin, pluginStatus := range pluginsStatus {
if pstatus, ok := pluginStatus.(map[string]interface{}); ok {
if pstatus["level"].(string) != string(dapi.StateAvailable) {
if pstatus["level"].(string) != string(esapi.StateAvailable) {
health.StateFailedReason[plugin] = strings.Join([]string{pstatus["level"].(string), pstatus["summary"].(string)}, ",")
}
} else {
Expand All @@ -102,5 +102,5 @@ func (h *EDClientV8) GetStateFromHealthResponse(health *Health) (dapi.DashboardS
return "", errors.New("Failed to parse overallStatus")
}

return dapi.DashboardServerState(health.OverallState), nil
return esapi.DashboardServerState(health.OverallState), nil
}
18 changes: 9 additions & 9 deletions elasticsearchdashboard/kubedb-client-builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"time"

catalog "kubedb.dev/apimachinery/apis/catalog/v1alpha1"
dapi "kubedb.dev/apimachinery/apis/dashboard/v1alpha1"
esapi "kubedb.dev/apimachinery/apis/elasticsearch/v1alpha1"
"kubedb.dev/apimachinery/apis/kubedb/v1alpha2"

"github.com/Masterminds/semver/v3"
Expand All @@ -40,7 +40,7 @@ import (

type KubeDBClientBuilder struct {
kc client.Client
dashboard *dapi.ElasticsearchDashboard
dashboard *esapi.ElasticsearchDashboard
db *v1alpha2.Elasticsearch
dbVersion *catalog.ElasticsearchVersion
authSecret *core.Secret
Expand All @@ -49,7 +49,7 @@ type KubeDBClientBuilder struct {
ctx context.Context
}

func NewKubeDBClientBuilder(kc client.Client, db *dapi.ElasticsearchDashboard) *KubeDBClientBuilder {
func NewKubeDBClientBuilder(kc client.Client, db *esapi.ElasticsearchDashboard) *KubeDBClientBuilder {
return &KubeDBClientBuilder{
kc: kc,
dashboard: db,
Expand Down Expand Up @@ -89,7 +89,7 @@ func (o *KubeDBClientBuilder) WithContext(ctx context.Context) *KubeDBClientBuil
func (o *KubeDBClientBuilder) GetElasticsearchDashboardClient() (*Client, error) {
config := Config{
host: getHostPath(o.dashboard),
api: dapi.KibanaStatusEndpoint,
api: esapi.KibanaStatusEndpoint,
transport: &http.Transport{
IdleConnTimeout: time.Second * 3,
DialContext: (&net.Dialer{
Expand All @@ -104,7 +104,7 @@ func (o *KubeDBClientBuilder) GetElasticsearchDashboardClient() (*Client, error)
var certSecret core.Secret
err := o.kc.Get(o.ctx, types.NamespacedName{
Namespace: o.dashboard.Namespace,
Name: o.dashboard.CertificateSecretName(dapi.ElasticsearchDashboardServerCert),
Name: o.dashboard.CertificateSecretName(esapi.ElasticsearchDashboardServerCert),
}, &certSecret)
if err != nil {
klog.Error(err, "failed to get serverCert secret")
Expand All @@ -121,8 +121,8 @@ func (o *KubeDBClientBuilder) GetElasticsearchDashboardClient() (*Client, error)
klog.Error(err, "failed to create certificate for TLS config")
return nil, err
}
clientCA.AppendCertsFromPEM(certSecret.Data[dapi.CaCertKey])
rootCA.AppendCertsFromPEM(certSecret.Data[dapi.CaCertKey])
clientCA.AppendCertsFromPEM(certSecret.Data[esapi.CaCertKey])
rootCA.AppendCertsFromPEM(certSecret.Data[esapi.CaCertKey])

config.transport.TLSClientConfig = &tls.Config{
Certificates: []tls.Certificate{crt},
Expand Down Expand Up @@ -199,6 +199,6 @@ func (o *KubeDBClientBuilder) GetElasticsearchDashboardClient() (*Client, error)

// return host path in
// format https://svc_name.namespace.svc:5601/api/status
func getHostPath(dashboard *dapi.ElasticsearchDashboard) string {
return fmt.Sprintf("%v://%s.%s.svc:%d", dashboard.GetConnectionScheme(), dashboard.ServiceName(), dashboard.GetNamespace(), dapi.ElasticsearchDashboardRESTPort)
func getHostPath(dashboard *esapi.ElasticsearchDashboard) string {
return fmt.Sprintf("%v://%s.%s.svc:%d", dashboard.GetConnectionScheme(), dashboard.ServiceName(), dashboard.GetNamespace(), esapi.ElasticsearchDashboardRESTPort)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
k8s.io/apimachinery v0.29.0
k8s.io/klog/v2 v2.110.1
kmodules.xyz/client-go v0.29.6
kubedb.dev/apimachinery v0.41.0-beta.0.0.20240115173822-556a36dfe734
kubedb.dev/apimachinery v0.41.0-beta.0.0.20240117131030-72d44aef7411
sigs.k8s.io/controller-runtime v0.16.3
xorm.io/xorm v1.3.6
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,8 @@ kmodules.xyz/monitoring-agent-api v0.29.0 h1:gpFl6OZrlMLb/ySMHdREI9EwGtnJ91oZBn9
kmodules.xyz/monitoring-agent-api v0.29.0/go.mod h1:iNbvaMTgVFOI5q2LJtGK91j4Dmjv4ZRiRdasGmWLKQI=
kmodules.xyz/offshoot-api v0.29.0 h1:GHLhxxT9jU1N8+FvOCCeJNyU5g0duYS46UGrs6AHNLY=
kmodules.xyz/offshoot-api v0.29.0/go.mod h1:5NxhBblXoDHWStx9HCDJR2KFTwYjEZ7i1Id3jelIunw=
kubedb.dev/apimachinery v0.41.0-beta.0.0.20240115173822-556a36dfe734 h1:o9vbQDfONuHUblmemfFrjt+bLvvN2rdQJk564i8IChc=
kubedb.dev/apimachinery v0.41.0-beta.0.0.20240115173822-556a36dfe734/go.mod h1:K49m/e80L1K/oJSMcaIDBTPCbzCpq5wU/o7sWOx81m0=
kubedb.dev/apimachinery v0.41.0-beta.0.0.20240117131030-72d44aef7411 h1:ZSVihIHPJfZSoegK5WGpSsVPTDZzHuaLsqOK9Hp+6Xg=
kubedb.dev/apimachinery v0.41.0-beta.0.0.20240117131030-72d44aef7411/go.mod h1:9iHsSfX02yJ6eA9IXSCruVjckH8wWgHB93ivpNVc1EY=
lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
lukechampine.com/uint128 v1.2.0 h1:mBi/5l91vocEN8otkC5bDLhi2KdCticRiwbdB0O+rjI=
lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
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/catalog"
"kubedb.dev/apimachinery/crds"

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

func (d DruidVersion) CustomResourceDefinition() *apiextensions.CustomResourceDefinition {
return crds.MustCustomResourceDefinition(SchemeGroupVersion.WithResource(ResourcePluralDruidVersion))
}

var _ apis.ResourceInfo = &DruidVersion{}

func (d DruidVersion) ResourceFQN() string {
return fmt.Sprintf("%s.%s", ResourcePluralDruidVersion, catalog.GroupName)
}

func (d DruidVersion) ResourceShortCode() string {
return ResourceCodeDruidVersion
}

func (d DruidVersion) ResourceKind() string {
return ResourceKindDruidVersion
}

func (d DruidVersion) ResourceSingular() string {
return ResourceSingularDruidVersion
}

func (d DruidVersion) ResourcePlural() string {
return ResourcePluralDruidVersion
}

func (d DruidVersion) ValidateSpecs() error {
if d.Spec.Version == "" ||
d.Spec.DB.Image == "" {
return fmt.Errorf(`atleast one of the following specs is not set for druidVersion "%v":
spec.version,
spec.db.image`, d.Name)
}
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
Copyright 2023.
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 (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
ResourceCodeDruidVersion = "drversion"
ResourceKindDruidVersion = "DruidVersion"
ResourceSingularDruidVersion = "druidversion"
ResourcePluralDruidVersion = "druidversions"
)

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

// +kubebuilder:object:root=true
// +kubebuilder:resource:path=druidversions,singular=druidversion,scope=Cluster,shortName=drversion,categories={datastore,kubedb,appscode}
// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.version"
// +kubebuilder:printcolumn:name="DB_IMAGE",type="string",JSONPath=".spec.db.image"
// +kubebuilder:printcolumn:name="Deprecated",type="boolean",JSONPath=".spec.deprecated"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
type DruidVersion struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec DruidVersionSpec `json:"spec,omitempty"`
}

// DruidVersionSpec defines the desired state of DruidVersion
type DruidVersionSpec struct {
// Version
Version string `json:"version"`
// Database Image
DB DruidVersionDatabase `json:"db"`
// Init Container Image
InitContainer DruidInitContainer `json:"initContainer"`
// Deprecated versions usable but regarded as obsolete and best avoided, typically due to having been superseded.
// +optional
Deprecated bool `json:"deprecated,omitempty"`
// PSP names
// +optional
PodSecurityPolicies DruidVersionPodSecurityPolicy `json:"podSecurityPolicies"`
// update constraints
UpdateConstraints UpdateConstraints `json:"updateConstraints,omitempty"`
// SecurityContext is for the additional security information for the Druid container
// +optional
SecurityContext DruidSecurityContext `json:"securityContext"`
}

// DruidVersionDatabase is the Druid Database image
type DruidVersionDatabase struct {
Image string `json:"image"`
}

// Druid is the Druid Init Container image
type DruidInitContainer struct {
Image string `json:"image"`
}

// SinglestoreVersionPodSecurityPolicy is the Singlestore pod security policies
type DruidVersionPodSecurityPolicy struct {
DatabasePolicyName string `json:"databasePolicyName"`
}

// DruidSecurityContext provides additional securityContext settings for the Druid Image
type DruidSecurityContext struct {
// RunAsUser is default UID for the DB container. It defaults to 1000.
RunAsUser *int64 `json:"runAsUser,omitempty"`

RunAsGroup *int64 `json:"runAsGroup,omitempty"`

// RunAsAnyNonRoot will be true if user can change the default UID to other than 1000.
RunAsAnyNonRoot bool `json:"runAsAnyNonRoot,omitempty"`
}

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

// DruidVersionList contains a list of DruidVersion
type DruidVersionList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []DruidVersion `json:"items,omitempty"`
}
Loading

0 comments on commit 9ee3a0f

Please sign in to comment.