Skip to content

Commit

Permalink
VZ-7840: Add support for OS dynamic plugin installation (#288)
Browse files Browse the repository at this point in the history
VZ-7840: Add support for dynamic plugin installation
  • Loading branch information
karan56625 committed Dec 9, 2022
1 parent b1e23e0 commit 6242ffe
Show file tree
Hide file tree
Showing 8 changed files with 317 additions and 22 deletions.
36 changes: 36 additions & 0 deletions k8s/crds/verrazzano.io_verrazzanomonitoringinstances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,23 @@ spec:
- javaOpts
type: object
type: array
plugins:
description: OpenSearchPlugins Enable to add 3rd Party / Custom
plugins not offered in the default OpenSearch image
properties:
enabled:
description: To enable or disable the non-bundled plugins
installation.
type: boolean
installList:
description: InstallList could be the list of plugin names,
URLs to the plugin zip file or Maven coordinates.
items:
type: string
type: array
required:
- enabled
type: object
policies:
items:
description: IndexManagementPolicy Defines a policy for managing
Expand Down Expand Up @@ -439,6 +456,25 @@ spec:
properties:
enabled:
type: boolean
plugins:
description: OpenSearchDashboardsPlugins is an alias of OpenSearchPlugins
as both have the same properties. Enable to add 3rd Party /
Custom plugins not offered in the default OpenSearch-Dashboards
image
properties:
enabled:
description: To enable or disable the non-bundled plugins
installation.
type: boolean
installList:
description: InstallList could be the list of plugin names,
URLs to the plugin zip file or Maven coordinates.
items:
type: string
type: array
required:
- enabled
type: object
replicas:
format: int32
type: integer
Expand Down
21 changes: 17 additions & 4 deletions pkg/apis/vmcontroller/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ type (
DataNode ElasticsearchNode `json:"dataNode,omitempty"`
Policies []IndexManagementPolicy `json:"policies,omitempty"`
Nodes []ElasticsearchNode `json:"nodes,omitempty"`
Plugins OpenSearchPlugins `json:"plugins,omitempty"`
}

// ElasticsearchNode Type details
Expand Down Expand Up @@ -169,14 +170,26 @@ type (
// Minimum count of documents in an index before it is rolled over
MinDocCount *int `json:"minDocCount,omitempty"`
}

// Kibana details
Kibana struct {
Enabled bool `json:"enabled" yaml:"enabled"`
Resources Resources `json:"resources,omitempty"`
Replicas int32 `json:"replicas,omitempty"`
Enabled bool `json:"enabled" yaml:"enabled"`
Resources Resources `json:"resources,omitempty"`
Replicas int32 `json:"replicas,omitempty"`
Plugins OpenSearchDashboardsPlugins `json:"plugins,omitempty"`
}

// OpenSearchPlugins Enable to add 3rd Party / Custom plugins not offered in the default OpenSearch image
OpenSearchPlugins struct {
// To enable or disable the non-bundled plugins installation.
Enabled bool `json:"enabled" yaml:"enabled"`
// InstallList could be the list of plugin names, URLs to the plugin zip file or Maven coordinates.
InstallList []string `json:"installList,omitempty"`
}

// OpenSearchDashboardsPlugins is an alias of OpenSearchPlugins as both have the same properties.
// Enable to add 3rd Party / Custom plugins not offered in the default OpenSearch-Dashboards image
OpenSearchDashboardsPlugins OpenSearchPlugins

// API details
API struct {
Replicas int32 `json:"replicas,omitempty"`
Expand Down
46 changes: 45 additions & 1 deletion pkg/apis/vmcontroller/v1/zz_generated.deepcopy.go

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

6 changes: 6 additions & 0 deletions pkg/resources/deployments/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,12 @@ func NewOpenSearchDashboardsDeployment(vmo *vmcontrollerv1.VerrazzanoMonitoringI
deployment.Spec.Template.Annotations = make(map[string]string)
}
deployment.Spec.Template.Annotations["traffic.sidecar.istio.io/includeOutboundPorts"] = fmt.Sprintf("%d", constants.OSHTTPPort)
// Adding command to install OS plugins at pod bootup
deployment.Spec.Template.Spec.Containers[0].Command = []string{
"sh",
"-c",
fmt.Sprintf(resources.OpenSearchDashboardCmdTmpl, resources.GetOSPluginsInstallTmpl(resources.GetOSDashboardPluginList(vmo), resources.OSDashboardPluginsInstallCmd)),
}
}

return deployment
Expand Down
11 changes: 9 additions & 2 deletions pkg/resources/deployments/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/verrazzano/verrazzano-monitoring-operator/pkg/resources"
"github.com/verrazzano/verrazzano-monitoring-operator/pkg/resources/nodes"
"github.com/verrazzano/verrazzano-monitoring-operator/pkg/util/memory"

"go.uber.org/zap"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -119,6 +120,12 @@ func (es ElasticsearchBasic) createElasticsearchIngestDeploymentElements(vmo *vm
if ingestDeployment.Spec.Template.Annotations == nil {
ingestDeployment.Spec.Template.Annotations = make(map[string]string)
}
// Adding command to install OS plugins at pod bootup
ingestDeployment.Spec.Template.Spec.Containers[0].Command = []string{
"sh",
"-c",
fmt.Sprintf(resources.OpenSearchIngestCmdTmpl, resources.GetOSPluginsInstallTmpl(resources.GetOpenSearchPluginList(vmo), resources.OSPluginsInstallCmd)),
}
ingestDeployment.Spec.Template.Annotations["traffic.sidecar.istio.io/excludeInboundPorts"] = fmt.Sprintf("%d", constants.OSTransportPort)
ingestDeployment.Spec.Template.Annotations["traffic.sidecar.istio.io/excludeOutboundPorts"] = fmt.Sprintf("%d", constants.OSTransportPort)
deployments = append(deployments, ingestDeployment)
Expand Down Expand Up @@ -216,11 +223,11 @@ func (es ElasticsearchBasic) createElasticsearchDataDeploymentElements(vmo *vmco
},
)

// Adding command for add keystore values at pod bootup
// Adding command for add keystore values and OS plugins installation at pod bootup
dataDeployment.Spec.Template.Spec.Containers[0].Command = []string{
"sh",
"-c",
resources.CreateOpenSearchContainerCMD(javaOpts),
resources.CreateOpenSearchContainerCMD(javaOpts, resources.GetOpenSearchPluginList(vmo)),
}

// add the required istio annotations to allow inter-es component communication
Expand Down
78 changes: 67 additions & 11 deletions pkg/resources/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package resources
import (
"crypto/rand"
"fmt"
netv1 "k8s.io/api/networking/v1"
"math/big"
"os"
"regexp"
Expand All @@ -16,7 +15,9 @@ import (
vmcontrollerv1 "github.com/verrazzano/verrazzano-monitoring-operator/pkg/apis/vmcontroller/v1"
"github.com/verrazzano/verrazzano-monitoring-operator/pkg/config"
"github.com/verrazzano/verrazzano-monitoring-operator/pkg/constants"

corev1 "k8s.io/api/core/v1"
netv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -28,11 +29,17 @@ var (
)

const (
serviceClusterLocal = ".svc.cluster.local"
masterHTTPEndpoint = "VMO_MASTER_HTTP_ENDPOINT"
dashboardsHTTPEndpoint = "VMO_DASHBOARDS_HTTP_ENDPOINT"
containerCmdTmpl = `#!/usr/bin/env bash -e
serviceClusterLocal = ".svc.cluster.local"
masterHTTPEndpoint = "VMO_MASTER_HTTP_ENDPOINT"
dashboardsHTTPEndpoint = "VMO_DASHBOARDS_HTTP_ENDPOINT"
OpenSearchIngestCmdTmpl = `#!/usr/bin/env bash -e
set -euo pipefail
%s
/usr/local/bin/docker-entrypoint.sh`
OpenSearchDashboardCmdTmpl = `#!/usr/bin/env bash -e
%s
/usr/local/bin/opensearch-dashboards-docker`
containerCmdTmpl = `#!/usr/bin/env bash -e
# Updating elastic search keystore with keys
# required for the repository-s3 plugin
if [ "${OBJECT_STORE_ACCESS_KEY_ID:-}" ]; then
Expand All @@ -45,6 +52,8 @@ const (
fi
%s
%s
/usr/local/bin/docker-entrypoint.sh`

Expand All @@ -53,6 +62,17 @@ const (
echo "Commenting out java heap settings in jvm.options..."
sed -i -e '/^-Xms/s/^/#/g' -e '/^-Xmx/s/^/#/g' config/jvm.options
`
OSPluginsInstallTmpl = `
set -euo pipefail
# Install OS plugins that are not bundled with OS
%s
`
OSPluginsInstallCmd = `
/usr/share/opensearch/bin/opensearch-plugin install -b %s
`
OSDashboardPluginsInstallCmd = `
/usr/share/opensearch-dashboards/bin/opensearch-dashboards-plugin install %s
`
)

// CopyImmutableEnvVars copies the initial master node environment variable from an existing container to an expected container
Expand Down Expand Up @@ -496,10 +516,13 @@ func ConvertToRegexp(pattern string) string {
return result.String()
}

// CreateElasticSearchContainerCMD creates the CMD for OpenSearch containers.
// The resulting CMD also contains command to comment java heap settings in config/jvm/options if input javaOpts is non-empty
// CreateOpenSearchContainerCMD creates the CMD for OpenSearch containers.
// The resulting CMD contains
// command to comment java heap settings in config/jvm/options if input javaOpts is non-empty
// OS plugins installation commands if OpenSearch plugins are provided
// and contains java min/max heap settings
func CreateOpenSearchContainerCMD(javaOpts string) string {
func CreateOpenSearchContainerCMD(javaOpts string, plugins []string) string {
pluginsInstallTmpl := GetOSPluginsInstallTmpl(plugins, OSPluginsInstallCmd)
if javaOpts != "" {
jvmOptsPair := strings.Split(javaOpts, " ")
minHeapMemory := ""
Expand All @@ -515,9 +538,42 @@ func CreateOpenSearchContainerCMD(javaOpts string) string {
}

if minHeapMemory != "" && maxHeapMemory != "" {
return fmt.Sprintf(containerCmdTmpl, jvmOptsDisableCmd)
return fmt.Sprintf(containerCmdTmpl, jvmOptsDisableCmd, pluginsInstallTmpl)
}
}

return fmt.Sprintf(containerCmdTmpl, "")
return fmt.Sprintf(containerCmdTmpl, "", pluginsInstallTmpl)
}

// GetOpenSearchPluginList retrieves the list of plugins provided in the VMI CRD for OpenSearch.
// GIVEN VMI CRD
// RETURN the list of provided os plugins. If there is no plugins in VMI CRD, empty list is returned.
func GetOpenSearchPluginList(vmo *vmcontrollerv1.VerrazzanoMonitoringInstance) []string {
if vmo.Spec.Elasticsearch.Enabled &&
vmo.Spec.Elasticsearch.Plugins.Enabled &&
len(vmo.Spec.Elasticsearch.Plugins.InstallList) > 0 {
return vmo.Spec.Elasticsearch.Plugins.InstallList
}
return []string{}
}

// GetOSDashboardPluginList retrieves the list of plugins provided in the VMI CRD for OpenSearch dashboard.
// GIVEN VMI CRD
// RETURN the list of provided OSD plugins. If there is no plugin in VMI CRD, an empty list is returned.
func GetOSDashboardPluginList(vmo *vmcontrollerv1.VerrazzanoMonitoringInstance) []string {
if vmo.Spec.Kibana.Enabled &&
vmo.Spec.Kibana.Plugins.Enabled &&
len(vmo.Spec.Kibana.Plugins.InstallList) > 0 {
return vmo.Spec.Kibana.Plugins.InstallList
}
return []string{}
}

// GetOSPluginsInstallTmpl returns the OSPluginsInstallTmpl by updating it with the given plugins and plugins installation cmd.
func GetOSPluginsInstallTmpl(plugins []string, osPluginInstallCmd string) string {
var pluginsInstallTmpl string
for _, plugin := range plugins {
pluginsInstallTmpl += fmt.Sprintf(OSPluginsInstallTmpl, fmt.Sprintf(osPluginInstallCmd, plugin))
}
return pluginsInstallTmpl
}
Loading

0 comments on commit 6242ffe

Please sign in to comment.