Skip to content

Commit

Permalink
cloudmon as deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
wanyaoqi committed Jun 30, 2020
1 parent e6356bf commit d5f78cd
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 463 deletions.
31 changes: 16 additions & 15 deletions pkg/apis/onecloud/v1alpha1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,21 +187,22 @@ func SetDefaults_OnecloudClusterSpec(obj *OnecloudClusterSpec, isEE bool) {
SetDefaults_StatefulDeploymentSpec(cType, spec.obj, spec.size, obj.ImageRepository, spec.version)
}

SetDefaults_CronJobSpec(&obj.CloudmonPing,
getImage(obj.ImageRepository, obj.CloudmonPing.Repository, APIGatewayComponentTypeEE,
obj.CloudmonPing.ImageName, obj.Version, obj.APIGateway.Tag))

SetDefaults_CronJobSpec(&obj.CloudmonReportUsage,
getImage(obj.ImageRepository, obj.CloudmonReportUsage.Repository, APIGatewayComponentTypeEE,
obj.CloudmonReportUsage.ImageName, obj.Version, obj.APIGateway.Tag))

SetDefaults_CronJobSpec(&obj.CloudmonReportServer,
getImage(obj.ImageRepository, obj.CloudmonReportServer.Repository, APIGatewayComponentTypeEE,
obj.CloudmonReportServer.ImageName, obj.Version, obj.APIGateway.Tag))

SetDefaults_CronJobSpec(&obj.CloudmonReportHost,
getImage(obj.ImageRepository, obj.CloudmonReportHost.Repository, APIGatewayComponentTypeEE,
obj.CloudmonReportHost.ImageName, obj.Version, obj.APIGateway.Tag))
// cloudmon spec
SetDefaults_DeploymentSpec(&obj.Cloudmon.DeploymentSpec,
getImage(obj.ImageRepository, obj.Cloudmon.Repository, APIGatewayComponentTypeEE,
obj.Cloudmon.ImageName, obj.Version, obj.APIGateway.Tag))
if obj.Cloudmon.CloudmonReportUsageDuration == 0 {
obj.Cloudmon.CloudmonReportUsageDuration = 15
}
if obj.Cloudmon.CloudmonReportServerDuration == 0 {
obj.Cloudmon.CloudmonReportServerDuration = 4
}
if obj.Cloudmon.CloudmonReportHostDuration == 0 {
obj.Cloudmon.CloudmonReportHostDuration = 4
}
if obj.Cloudmon.CloudmonPingDuration == 0 {
obj.Cloudmon.CloudmonPingDuration = 5
}
}

func SetDefaults_Mysql(obj *Mysql) {
Expand Down
20 changes: 12 additions & 8 deletions pkg/apis/onecloud/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ const (
CloudmonReportServerComponentType ComponentType = "cloudmon-report-server"
// CloudmonReportHost is report-host cronjob
CloudmonReportHostComponentType ComponentType = "cloudmon-report-host"
// Cloudmon is report monitor data deployment
CloudmonComponentType ComponentType = "cloudmon"
// Esxi Agent
EsxiAgentComponentType ComponentType = "esxi-agent"
// Onecloud Reource Operator
Expand Down Expand Up @@ -233,14 +235,8 @@ type OnecloudClusterSpec struct {
Meter StatefulDeploymentSpec `json:"meter"`
// AutoUpdate holds configuration for autoupdate
AutoUpdate DeploymentSpec `json:"autoupdate"`
// CloudmonPing holds configuration for ping-probe cronjob
CloudmonPing CronJobSpec `json:"cloudmonping"`
// CloudmonReportUsage holds configuration for report-usage cronjob
CloudmonReportUsage CronJobSpec `json:"cloudmonreportusage"`
// CloudmonReportServerAli holds configuration for report-server cronjob
CloudmonReportServer CronJobSpec `json:"cloudmonreportserver"`
// CloudmonReportHost holds configuration for report-usage cronjob
CloudmonReportHost CronJobSpec `json:"cloudmonreporthost"`
// Cloudmon holds configuration for report monitor data
Cloudmon CloudmonSpec `json:"cloudmon"`
// EsxiAgent hols configuration for esxi agent
EsxiAgent StatefulDeploymentSpec `json:"esxiagent"`
// Itsm holds configuration for itsm service
Expand Down Expand Up @@ -453,6 +449,14 @@ type RegionSpec struct {
DNSDomain string `json:"dnsDomain"`
}

type CloudmonSpec struct {
DeploymentSpec
CloudmonPingDuration uint
CloudmonReportHostDuration uint
CloudmonReportServerDuration uint
CloudmonReportUsageDuration uint
}

type RegionDNSProxy struct {
// check: https://coredns.io/plugins/proxy/
From string `json:"from"`
Expand Down
25 changes: 21 additions & 4 deletions pkg/apis/onecloud/v1alpha1/zz_generated.deepcopy.go

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

12 changes: 12 additions & 0 deletions pkg/controller/base_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,15 @@ func (c *baseControl) RecordUpdateEvent(oc *v1alpha1.OnecloudCluster, obj Object
func (c *baseControl) RecordDeleteEvent(oc *v1alpha1.OnecloudCluster, obj Object, err error) {
recordDeleteEvent(c.Recorder(), oc, c.Kind(), obj, err)
}

type fakeObject struct {
name string
}

func (o *fakeObject) GetName() string {
return o.name
}

func newFakeObject(name string) *fakeObject {
return &fakeObject{name: name}
}
5 changes: 1 addition & 4 deletions pkg/controller/cluster/onecloud_cluster_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,17 @@ func (occ *defaultClusterControl) updateOnecloudCluster(oc *v1alpha1.OnecloudClu
components.Yunionconf(),
components.Monitor(),
components.S3gateway(),
components.CloudmonPing(),
components.CloudmonReportUsage(),
components.Notify(),
components.Host(),
components.HostDeployer(),
components.HostImage(),
components.VpcAgent(),
components.Baremetal(),
components.CloudmonReportServer(),
components.CloudmonReportHost(),
components.ServiceOperator(),
components.Itsm(),
components.Telegraf(),
components.CloudId(),
components.Cloudmon(),
}
var grp errgroup.Group
for _, component := range dependComponents {
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/cronjob_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
type CronJobControlInterface interface {
CreateCronJob(*v1alpha1.OnecloudCluster, *batchv1.CronJob) error
UpdateCronJob(*v1alpha1.OnecloudCluster, *batchv1.CronJob) (*batchv1.CronJob, error)
DeleteCronJob(*v1alpha1.OnecloudCluster, *batchv1.CronJob) error
DeleteCronJob(*v1alpha1.OnecloudCluster, string) error
}

type cronJobControl struct {
Expand Down Expand Up @@ -76,9 +76,9 @@ func (c *cronJobControl) UpdateCronJob(
}

func (c *cronJobControl) DeleteCronJob(
oc *v1alpha1.OnecloudCluster, cronJob *batchv1.CronJob,
oc *v1alpha1.OnecloudCluster, cronJobName string,
) error {
err := c.kubeCli.BatchV1beta1().CronJobs(oc.Namespace).Delete(cronJob.Name, nil)
c.RecordDeleteEvent(oc, cronJob, err)
err := c.kubeCli.BatchV1beta1().CronJobs(oc.Namespace).Delete(cronJobName, nil)
c.RecordDeleteEvent(oc, newFakeObject(cronJobName), err)
return err
}
8 changes: 4 additions & 4 deletions pkg/controller/deployment_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type DeploymentControlInterface interface {
// UpdateDeployment updates a deployment in a OnecloudCluster.
UpdateDeployment(*v1alpha1.OnecloudCluster, *apps.Deployment) (*apps.Deployment, error)
// DeleteDeployment deletes a deployment in a OnecloudCluster.
DeleteDeployment(*v1alpha1.OnecloudCluster, *apps.Deployment) error
DeleteDeployment(*v1alpha1.OnecloudCluster, string) error
}

type realDeploymentControl struct {
Expand Down Expand Up @@ -90,8 +90,8 @@ func (c *realDeploymentControl) UpdateDeployment(oc *v1alpha1.OnecloudCluster, d
return updatedDeploy, err
}

func (c *realDeploymentControl) DeleteDeployment(oc *v1alpha1.OnecloudCluster, deploy *apps.Deployment) error {
err := c.kubeCli.AppsV1beta1().Deployments(oc.Namespace).Delete(deploy.Name, nil)
c.RecordDeleteEvent(oc, deploy, err)
func (c *realDeploymentControl) DeleteDeployment(oc *v1alpha1.OnecloudCluster, deploymentName string) error {
err := c.kubeCli.AppsV1beta1().Deployments(oc.Namespace).Delete(deploymentName, nil)
c.RecordDeleteEvent(oc, newFakeObject(deploymentName), err)
return err
}
100 changes: 100 additions & 0 deletions pkg/manager/component/cloudmon.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package component

import (
"fmt"

apps "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"

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

type cloudmonManager struct {
*ComponentManager
}

func newCloudMonManager(man *ComponentManager) manager.Manager {
return &cloudmonManager{man}
}

func (m *cloudmonManager) ensureOldCronjobsDeleted(oc *v1alpha1.OnecloudCluster) error {
for _, componentType := range []v1alpha1.ComponentType{
v1alpha1.CloudmonPingComponentType, v1alpha1.CloudmonReportHostComponentType,
v1alpha1.CloudmonReportServerComponentType, v1alpha1.CloudmonReportUsageComponentType,
} {
err := m.cronControl.DeleteCronJob(oc, controller.NewClusterComponentName(oc.GetName(), componentType))
if err != nil && !errors.IsNotFound(err) {
return err
}
}
return nil
}

func (m *cloudmonManager) Sync(oc *v1alpha1.OnecloudCluster) error {
if err := m.ensureOldCronjobsDeleted(oc); err != nil {
return err
}
if !IsEnterpriseEdition(oc) {
if err := m.deployControl.DeleteDeployment(
oc, controller.NewClusterComponentName(oc.GetName(), v1alpha1.CloudmonComponentType),
); err != nil && !errors.IsNotFound(err) {
return err
}
return nil
}
return syncComponent(m, oc, oc.Spec.Cloudmon.Disable)
}

func (m *cloudmonManager) getDeployment(oc *v1alpha1.OnecloudCluster, cfg *v1alpha1.OnecloudClusterConfig) (*apps.Deployment, error) {
spec := oc.Spec.Cloudmon.DeploymentSpec
configMap := controller.ComponentConfigMapName(oc, v1alpha1.APIGatewayComponentType)
h := NewVolumeHelper(oc, configMap, v1alpha1.APIGatewayComponentType)
containersF := func(volMounts []corev1.VolumeMount) []corev1.Container {
return []corev1.Container{
{
Name: v1alpha1.CloudmonComponentType.String(),
Image: spec.Image,
Command: []string{"/bin/sh", "-c", fmt.Sprintf(`
# = = = = = = = ping probe = = = = = = =
echo '*/%d * * * * /opt/yunion/bin/cloudmon --config /etc/yunion/%s.conf ping-probe 2>&1' > /etc/crontabs/root
# = = = = = = = report host = = = = = = =
echo '*/%d * * * * /opt/yunion/bin/cloudmon --config /etc/yunion/%s.conf report-host --interval %d --provider VMware 2>&1' >> /etc/crontabs/root
echo '*/%d * * * * /opt/yunion/bin/cloudmon --config /etc/yunion/%s.conf report-host --interval %d --provider ZStack 2>&1' >> /etc/crontabs/root
# = = = = = = = report server = = = = = = =
echo '*/%d * * * * /opt/yunion/bin/cloudmon --config /etc/yunion/%s.conf report-server --interval %d --provider Aliyun 2>&1' >> /etc/crontabs/root
echo '*/%d * * * * /opt/yunion/bin/cloudmon --config /etc/yunion/%s.conf report-server --interval %d --provider Huawei 2>&1' >> /etc/crontabs/root
echo '*/%d * * * * /opt/yunion/bin/cloudmon --config /etc/yunion/%s.conf report-server --interval %d --provider Qcloud 2>&1' >> /etc/crontabs/root
echo '*/%d * * * * /opt/yunion/bin/cloudmon --config /etc/yunion/%s.conf report-server --interval %d --provider Google 2>&1' >> /etc/crontabs/root
echo '*/%d * * * * /opt/yunion/bin/cloudmon --config /etc/yunion/%s.conf report-server --interval %d --provider Aws 2>&1' >> /etc/crontabs/root
echo '*/%d * * * * /opt/yunion/bin/cloudmon --config /etc/yunion/%s.conf report-server --interval %d --provider Azure 2>&1' >> /etc/crontabs/root
echo '*/%d * * * * /opt/yunion/bin/cloudmon --config /etc/yunion/%s.conf report-server --interval %d --provider VMware 2>&1' >> /etc/crontabs/root
echo '*/%d * * * * /opt/yunion/bin/cloudmon --config /etc/yunion/%s.conf report-server --interval %d --provider ZStack 2>&1' >> /etc/crontabs/root
# = = = = = = = report usage = = = = = = =
echo '*/%d * * * * /opt/yunion/bin/cloudmon --config /etc/yunion/%s.conf report-usage 2>&1' >> /etc/crontabs/root
crond -f -d 8
`, oc.Spec.Cloudmon.CloudmonPingDuration, v1alpha1.APIGatewayComponentType,
oc.Spec.Cloudmon.CloudmonReportHostDuration, v1alpha1.APIGatewayComponentType, oc.Spec.Cloudmon.CloudmonReportHostDuration,
oc.Spec.Cloudmon.CloudmonReportHostDuration, v1alpha1.APIGatewayComponentType, oc.Spec.Cloudmon.CloudmonReportHostDuration,
oc.Spec.Cloudmon.CloudmonReportServerDuration, v1alpha1.APIGatewayComponentType, oc.Spec.Cloudmon.CloudmonReportServerDuration,
oc.Spec.Cloudmon.CloudmonReportServerDuration, v1alpha1.APIGatewayComponentType, oc.Spec.Cloudmon.CloudmonReportServerDuration,
oc.Spec.Cloudmon.CloudmonReportServerDuration, v1alpha1.APIGatewayComponentType, oc.Spec.Cloudmon.CloudmonReportServerDuration,
oc.Spec.Cloudmon.CloudmonReportServerDuration, v1alpha1.APIGatewayComponentType, oc.Spec.Cloudmon.CloudmonReportServerDuration,
oc.Spec.Cloudmon.CloudmonReportServerDuration, v1alpha1.APIGatewayComponentType, oc.Spec.Cloudmon.CloudmonReportServerDuration,
oc.Spec.Cloudmon.CloudmonReportServerDuration, v1alpha1.APIGatewayComponentType, oc.Spec.Cloudmon.CloudmonReportServerDuration,
oc.Spec.Cloudmon.CloudmonReportServerDuration, v1alpha1.APIGatewayComponentType, oc.Spec.Cloudmon.CloudmonReportServerDuration,
oc.Spec.Cloudmon.CloudmonReportServerDuration, v1alpha1.APIGatewayComponentType, oc.Spec.Cloudmon.CloudmonReportServerDuration,
oc.Spec.Cloudmon.CloudmonReportUsageDuration, v1alpha1.APIGatewayComponentType,
)},
ImagePullPolicy: spec.ImagePullPolicy,
VolumeMounts: volMounts,
},
}
}
return m.newDefaultDeployment(
v1alpha1.CloudmonComponentType, oc, h,
spec, nil, containersF,
)
}
62 changes: 0 additions & 62 deletions pkg/manager/component/cloudmon_ping.go

This file was deleted.

0 comments on commit d5f78cd

Please sign in to comment.