Skip to content

Commit

Permalink
Merge pull request #6 from yunionio/feature/componets-cmd
Browse files Browse the repository at this point in the history
add extra componets command
  • Loading branch information
zexi authored Sep 19, 2019
2 parents 1e451ff + 2bc8f61 commit 29de0a3
Show file tree
Hide file tree
Showing 84 changed files with 6,915 additions and 6,934 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export GO111MODULE:=on

build:
go build -o ./_output/bin/ocadm cmd/main.go
go build -mod vendor -o ./_output/bin/ocadm cmd/main.go

generate:
./hack/codegen.sh
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/evanphx/json-patch v4.5.0+incompatible // indirect
github.com/ghodss/yaml v1.0.0
github.com/go-logr/logr v0.1.0 // indirect
github.com/go-logr/zapr v0.1.1 // indirect
github.com/go-sql-driver/mysql v1.4.1
Expand All @@ -38,7 +39,7 @@ require (
sigs.k8s.io/testing_frameworks v0.1.1 // indirect
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051
yunion.io/x/onecloud v0.0.0-20190725062408-c88eae5261a2
yunion.io/x/onecloud-operator v0.0.1-alpha2
yunion.io/x/onecloud-operator v0.0.1-alpha2.0.20190919062109-f48871684b03
yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30
)

Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,10 @@ yunion.io/x/onecloud-operator v0.0.1-alpha1 h1:DXF5obHcgC/pCxgDtPMmMoN6kFB/ZUJA4
yunion.io/x/onecloud-operator v0.0.1-alpha1/go.mod h1:1Y0lBz6YecMrLPUHo80qOoy+oyRsYK4HwNCM1uvFJ5w=
yunion.io/x/onecloud-operator v0.0.1-alpha2 h1:Ll/joHtzVESvTj02NEg2l3EXb+WBe0xoUQFIGilS3G4=
yunion.io/x/onecloud-operator v0.0.1-alpha2/go.mod h1:bxo6Vuns1t08MRBy4OeQtlDKcg9ghO0znmNi3iYaXRk=
yunion.io/x/onecloud-operator v0.0.1-alpha2.0.20190911123136-955e28308bd6 h1:GUQVMRmzt7g65wyQOQict5xbad00kpKSvADsu54Ab6U=
yunion.io/x/onecloud-operator v0.0.1-alpha2.0.20190911123136-955e28308bd6/go.mod h1:bxo6Vuns1t08MRBy4OeQtlDKcg9ghO0znmNi3iYaXRk=
yunion.io/x/onecloud-operator v0.0.1-alpha2.0.20190919062109-f48871684b03 h1:igpPcvA6M2uW1NJQqJaGUwMXX4o12fvxmHNdaayQEaw=
yunion.io/x/onecloud-operator v0.0.1-alpha2.0.20190919062109-f48871684b03/go.mod h1:bxo6Vuns1t08MRBy4OeQtlDKcg9ghO0znmNi3iYaXRk=
yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf h1:OsKC+2ghZHwp+Ztm/MwKlLKKRiE7QcPG8eTp0GmsHbg=
yunion.io/x/pkg v0.0.0-20190620104149-945c25821dbf/go.mod h1:t6rEGG2sQ4J7DhFxSZVOTjNd0YO/KlfWQyK1W4tog+E=
yunion.io/x/pkg v0.0.0-20190628082551-f4033ba2ea30 h1:6CkrwtX4xeYFqqpdWtQPAVqEnD3aEivPLOLzNKNPAB0=
Expand Down
162 changes: 162 additions & 0 deletions hack/migrate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#!/bin/bash

set -e

GLOBALRC_FILE=${GLOBALRC_FILE:-/opt/cloud/workspace/globalrc}
VARS_FILE=${VARS_FILE:-/opt/yunionsetup/vars}

error_exit() {
echo "Error: $1"
exit 1
}

check_file_exists() {
local file=$1
if [ ! -f "$file" ]; then
error_exit "file $file not exists"
fi
}

new_cluster_yaml() {
local rc_file=$GLOBALRC_FILE
local vars_file=$VARS_FILE

check_file_exists $rc_file
check_file_exists $vars_file

source $rc_file
source $vars_file

cat <<EOF
---
# onecloud cluster core components config
apiVersion: v1
kind: ConfigMap
metadata:
name: default-cluster-config
namespace: onecloud
data:
OnecloudClusterConfig: |
apiVersion: onecloud.yunion.io/v1alpha1
kind: OnecloudClusterConfig
apiGateway:
username: "$YUNIONAPI_ADMIN_USER"
password: "$YUNIONAPI_ADMIN_PASS"
glance:
db:
database: "$MYSQL_DB_GLANCE"
username: "$MYSQL_USER_GLANCE"
password: "$MYSQL_PASS_GLANCE"
username: "$GLANCE_ADMIN_USER"
password: "$GLANCE_ADMIN_PASS"
keystone:
db:
database: "$MYSQL_DB_KEYSTONE"
username: "$MYSQL_USER_KEYSTONE"
password: "$MYSQL_PASS_KEYSTONE"
kubeserver:
db:
database: "$MYSQL_DB_KUBE"
username: "$MYSQL_USER_KUBE"
password: "$MYSQL_PASS_KUBE"
username: "$YUNION_KUBE_SERVER_ADMIN_USER"
password: "$YUNION_KUBE_SERVER_ADMIN_PASS"
logger:
db:
database: "$MYSQL_DB_LOGGER"
username: "$MYSQL_USER_LOGGER"
password: "$MYSQL_PASS_LOGGER"
username: "$LOGGER_ADMIN_USER"
password: "$LOGGER_ADMIN_PASS"
region:
db:
database: "$MYSQL_DB_REGION"
username: "$MYSQL_USER_REGION"
password: "$MYSQL_PASS_REGION"
username: "$REGION_ADMIN_USER"
password: "$REGION_ADMIN_PASS"
webconsole:
username: "$YUNION_WEBCONSOLE_ADMIN_USER"
password: "$YUNION_WEBCONSOLE_ADMIN_PASS"
yunionagent:
db:
database: "$MYSQL_DB_YUNIONAGENT"
username: "$MYSQL_USER_YUNIONAGENT"
password: "$MYSQL_PASS_YUNIONAGENT"
username: "$YUNIONAGENT_ADMIN_USER"
password: "$YUNIONAGENT_ADMIN_PASS"
yunionconf:
db:
database: "$MYSQL_DB_YUNIONCONF"
username: "$MYSQL_USER_YUNIONCONF"
password: "$MYSQL_PASS_YUNIONCONF"
username: "$YUNIONCONF_ADMIN_USER"
password: "$YUNIONCONF_ADMIN_PASS"
---
# onecloud cluster misc components config
apiVersion: v1
kind: ConfigMap
metadata:
name: default-cluster-components-config
namespace: onecloud
data:
OnecloudComponentsConfig: |
cloudmon:
username: "$YUNION_CLOUDMON_DOCKER_USER"
password: "$YUNION_CLOUDMON_DOCKER_PSWD"
cloudwatcher:
db:
database: "$MYSQL_DB_CLOUDWATCHER"
username: "$MYSQL_USER_CLOUDWATCHER"
password: "$MYSQL_PASS_CLOUDWATCHER"
username: "$YUNION_CLOUDWATCHER_DOCKER_USER"
password: "$YUNION_CLOUDWATCHER_DOCKER_PSWD"
itsm:
encryptionKey: "$ITSM_ENCRYPTION_KEY"
secondDatabase: "$MYSQL_DB_ITSM_SECONDARY"
db:
database: "$MYSQL_DB_ITSM_PRIMARY"
username: "$MYSQL_USER_ITSM_PRIMARY"
password: "$MYSQL_PASS_ITSM"
username: "$YUNION_ITSM_DOCKER_USER"
password: "$YUNION_ITSM_DOCKER_PSWD"
meter:
db:
database: "$MYSQL_DB_METER"
username: "$MYSQL_USER_METER"
password: "$MYSQL_PASS_METER"
username: "$YUNION_METER_DOCKER_USER"
password: "$YUNION_METER_DOCKER_PSWD"
meteralert:
db:
database: "$MYSQL_DB_METERALERT"
username: "$MYSQL_USER_METERALERT"
password: "$MYSQL_PASS_METERALERT"
username: "$YUNION_METERALERT_DOCKER_USER"
password: "$YUNION_METERALERT_DOCKER_PSWD"
---
# default onecloud cluster
apiVersion: onecloud.yunion.io/v1alpha1
kind: OnecloudCluster
metadata:
name: default
namespace: onecloud
spec:
loadBalancerEndpoint: "$MANAGEMENT_IP"
imageRepository: registry.cn-beijing.aliyuncs.com/yunionio
mysql:
host: "$MYSQL_HOST"
password: "$MYSQL_ROOT_PASSWORD"
port: $MYSQL_PORT
username: root
region: "$REGION"
zone: "$ZONE"
keystone:
bootstrapPassword: "$SYSADMIN_PASSWORD"
glance:
nodeSelector:
kubernetes.io/hostname: glance-node
EOF
}

new_cluster_yaml
1 change: 1 addition & 0 deletions pkg/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func NewOneCloudAdminCommand(in io.Reader, out, err io.Writer) (*cobra.Command,
cmds.AddCommand(NewCmdReset(in, out, nil))
cmds.AddCommand(NewCmdToken(out, err))
cmds.AddCommand(NewCmdCluster(out))
cmds.AddCommand(NewCmdComponent(out))

commandFns := []func() *cobra.Command{
//kubeadm,
Expand Down
21 changes: 21 additions & 0 deletions pkg/cmd/component.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import (
"io"

"github.com/spf13/cobra"

componentphase "yunion.io/x/ocadm/pkg/phases/component"
)

func NewCmdComponent(out io.Writer) *cobra.Command {
cmds := &cobra.Command{
Use: "component",
Short: "Manage onecloud extra components",
}
cmds.AddCommand(componentphase.EnableCmd.GetCmd())
cmds.AddCommand(componentphase.DisableCmd.GetCmd())
cmds.AddCommand(componentphase.NewCmdConfig(out))
cmds.AddCommand(componentphase.NewCmdWeb())
return cmds
}
2 changes: 1 addition & 1 deletion pkg/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"io"
"strings"
"yunion.io/x/ocadm/pkg/apis/scheme"

"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand All @@ -16,6 +15,7 @@ import (
utilruntime "k8s.io/kubernetes/cmd/kubeadm/app/util/runtime"
utilsexec "k8s.io/utils/exec"

"yunion.io/x/ocadm/pkg/apis/scheme"
apiv1 "yunion.io/x/ocadm/pkg/apis/v1"
"yunion.io/x/ocadm/pkg/images"
configutil "yunion.io/x/ocadm/pkg/util/config"
Expand Down
88 changes: 88 additions & 0 deletions pkg/phases/component/cloudmon.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package component

import (
apps "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"

onecloud "yunion.io/x/onecloud-operator/pkg/apis/onecloud/v1alpha1"
)

const (
CloudMonConfigTemplate = `
debug=false
trace=false
logging.level.com.yunion.cloudmon=INFO
yunion.rc.auth.url={{.AuthURL}}
yunion.rc.auth.domain={{.AuthDomain}}
yunion.rc.auth.username={{.AuthUsername}}
yunion.rc.auth.password={{.AuthPassword}}
yunion.rc.auth.project={{.AuthProject}}
yunion.rc.auth.region={{.Region}}
yunion.rc.auth.cache-size=500
yunion.rc.auth.timeout=1000
yunion.rc.auth.debug=true
yunion.rc.auth.insecure=true
yunion.rc.auth.refresh-interval=300000
yunion.rc.async-job.initial-delay=2000
yunion.rc.async-job.fixed-rate=300000
yunion.rc.async-job.fixed-thread-pool=10
yunion.rc.influxdb.database=telegraf
yunion.rc.influxdb.policy=30day_only
yunion.rc.influxdb.measurement=instance
yunion.rc.metrics.ins.providers=Aliyun,Azure,Aws,Qcloud,VMWare,Huawei,Openstack,Ucloud,ZStack
yunion.rc.metrics.eip.providers=Aliyun,Qcloud
`
)

var CloudMonComponent IComponent = NewCloudMon()

type CloudMon struct {
*BaseComponent
}

func NewCloudMon() *CloudMon {
m := new(CloudMon)
m.BaseComponent = NewBaseComponent(onecloud.ComponentType("cloudmon"), m)
return m
}

func (m CloudMon) NewDeployment(oc *onecloud.OnecloudCluster) (*apps.Deployment, error) {
cf := func(volMounts []corev1.VolumeMount) []corev1.Container {
volMounts = SetJavaConfigVolumeMounts(volMounts)
return []corev1.Container{
{
Name: "cloudmon",
Image: GetImage(oc, m.GetComponentType(), ""),
Env: []corev1.EnvVar{
{
Name: JAVA_APP_JAR,
Value: "cloudmon.jar",
},
},
VolumeMounts: volMounts,
},
}
}
cType := m.GetComponentType()
deploy, err := NewDefaultDeployment(cType, oc, NewVolumeHelper(oc, cType), cf)
if err != nil {
return nil, err
}
podSpec := &deploy.Spec.Template.Spec
podSpec.Volumes = SetJavaConfigVolumes(podSpec.Volumes)
return deploy, nil
}

func (m CloudMon) NewConfigMap(oc *onecloud.OnecloudCluster, cCfg *OnecloudComponentsConfig) (*corev1.ConfigMap, error) {
cfg := cCfg.CloudmonConfig
config := NewJavaBaseConfig(oc, cfg.Port, cfg.Username, cfg.Password)
return NewConfigMapByTemplate(m.GetComponentType(), oc, CloudMonConfigTemplate, config)
}

func (m CloudMon) NewCloudUser(cfg *OnecloudComponentsConfig) *onecloud.CloudUser {
return &cfg.CloudmonConfig.CloudUser
}
Loading

0 comments on commit 29de0a3

Please sign in to comment.