Skip to content

Commit

Permalink
feature: add cloudid service
Browse files Browse the repository at this point in the history
  • Loading branch information
Qu Xuan committed Jun 22, 2020
1 parent c15c704 commit 525f310
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/apis/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ const (
CloudeventDB = "yunioncloudevent"
CloudeventDBUser = "yunioncloudevent"

CloudIdAdminUser = "cloudidadmin"
CloudIdAdminProject = SysAdminProject
CloudIdPort = 30893
CloudIdDB = "yunioncloudid"
CloudIdDBUser = "yunioncloudid"

EndpointTypeInternal = "internal"
EndpointTypePublic = "public"
EndpointTypeAdmin = "admin"
Expand Down Expand Up @@ -225,6 +231,9 @@ const (
ServiceNameCloudevent = "cloudevent"
ServiceTypeCloudevent = "cloudevent"

ServiceNameCloudId = "cloudid"
ServiceTypeCloudId = "cloudid"

ServiceNameNotify = "notify"
ServiceTypeNotify = "notify"

Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/onecloud/v1alpha1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package v1alpha1

import (
"fmt"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/rand"
Expand Down Expand Up @@ -119,6 +120,7 @@ func SetDefaults_OnecloudClusterSpec(obj *OnecloudClusterSpec, isEE bool) {
MonitorComponentType: &obj.Monitor,
ServiceOperatorComponentType: &obj.ServiceOperator,
ItsmComponentType: &obj.Itsm,
CloudIdComponentType: &obj.CloudId,
} {
SetDefaults_DeploymentSpec(spec, getImage(obj.ImageRepository, spec.Repository, cType, spec.ImageName, obj.Version, spec.Tag))
}
Expand Down Expand Up @@ -381,6 +383,7 @@ func SetDefaults_OnecloudClusterConfig(obj *OnecloudClusterConfig) {
&obj.Meter.ServiceDBCommonOptions: {constants.MeterAdminUser, constants.MeterPort, constants.MeterDB, constants.MeterDBUser},
&obj.Monitor: {constants.MonitorAdminUser, constants.MonitorPort, constants.MonitorDB, constants.MonitorDBUser},
&obj.Itsm.ServiceDBCommonOptions: {constants.ItsmAdminUser, constants.ItsmPort, constants.ItsmDB, constants.ItsmDBUser},
&obj.CloudId: {constants.CloudIdAdminUser, constants.CloudIdPort, constants.CloudIdDB, constants.CloudIdDBUser},
} {
if user, ok := registryPorts[tmp.port]; ok {
log.Fatalf("port %d has been registered by %s", tmp.port, user)
Expand Down
6 changes: 6 additions & 0 deletions pkg/apis/onecloud/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const (
ItsmComponentType ComponentType = "itsm"
// Telegraf is monitor agent component type
TelegrafComponentType ComponentType = "telegraf"
CloudIdComponentType ComponentType = "cloudid"
)

// ComponentPhase is the current state of component
Expand Down Expand Up @@ -250,6 +251,9 @@ type OnecloudClusterSpec struct {

OvnNorth DeploymentSpec `json:"ovnNorth"`
VpcAgent DeploymentSpec `json:"vpcAgent"`

// Cloudid holds configuration for cloudid service
CloudId DeploymentSpec `json:"cloudid"`
}

// OnecloudClusterStatus describes cluster status
Expand Down Expand Up @@ -281,6 +285,7 @@ type OnecloudClusterStatus struct {
VpcAgent DeploymentStatus `json:"vpcAgent,omitempty"`
Etcd EctdStatus `json:"etcd,omitempty"`
Itsm DeploymentStatus `json:"itsm,omitempty"`
CloudId DeploymentStatus `json:"cloudid,omitempty"`
}

type Etcd struct {
Expand Down Expand Up @@ -597,4 +602,5 @@ type OnecloudClusterConfig struct {
VpcAgent VpcAgentConfig `json:"vpcagent"`
ServiceOperator ServiceCommonOptions `json:"onecloudServiceOperator"`
Itsm ItsmConfig `json:"itsm"`
CloudId ServiceDBCommonOptions `json:"cloudid"`
}
1 change: 1 addition & 0 deletions pkg/controller/cluster/onecloud_cluster_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func (occ *defaultClusterControl) updateOnecloudCluster(oc *v1alpha1.OnecloudClu
components.ServiceOperator(),
components.Itsm(),
components.Telegraf(),
components.CloudId(),
}
var grp errgroup.Group
for _, component := range dependComponents {
Expand Down
96 changes: 96 additions & 0 deletions pkg/manager/component/cloudid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright 2019 Yunion
//
// 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 component

import (
"path"

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

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

type cloudidManager struct {
*ComponentManager
}

func newCloudIdManager(man *ComponentManager) manager.Manager {
return &cloudidManager{man}
}

func (m *cloudidManager) Sync(oc *v1alpha1.OnecloudCluster) error {
return syncComponent(m, oc, oc.Spec.CloudId.Disable)
}

func (m *cloudidManager) getDBConfig(cfg *v1alpha1.OnecloudClusterConfig) *v1alpha1.DBConfig {
return &cfg.CloudId.DB
}

func (m *cloudidManager) getCloudUser(cfg *v1alpha1.OnecloudClusterConfig) *v1alpha1.CloudUser {
return &cfg.CloudId.CloudUser
}

func (m *cloudidManager) getPhaseControl(man controller.ComponentManager) controller.PhaseControl {
return controller.NewRegisterEndpointComponent(man, v1alpha1.CloudIdComponentType,
constants.ServiceNameCloudId, constants.ServiceTypeCloudId,
constants.CloudIdPort, "")
}

func (m *cloudidManager) getConfigMap(oc *v1alpha1.OnecloudCluster, cfg *v1alpha1.OnecloudClusterConfig) (*corev1.ConfigMap, error) {
opt := &options.Options
if err := SetOptionsDefault(opt, constants.ServiceTypeCloudId); err != nil {
return nil, err
}
config := cfg.CloudId
SetDBOptions(&opt.DBOptions, oc.Spec.Mysql, config.DB)
SetOptionsServiceTLS(&opt.BaseOptions)
SetServiceCommonOptions(&opt.CommonOptions, oc, config.ServiceCommonOptions)
opt.AutoSyncTable = true
opt.SslCertfile = path.Join(constants.CertDir, constants.ServiceCertName)
opt.SslKeyfile = path.Join(constants.CertDir, constants.ServiceKeyName)
opt.Port = constants.CloudIdPort
return m.newServiceConfigMap(v1alpha1.CloudIdComponentType, oc, opt), nil
}

func (m *cloudidManager) getService(oc *v1alpha1.OnecloudCluster) []*corev1.Service {
return []*corev1.Service{m.newSingleNodePortService(v1alpha1.CloudIdComponentType, oc, constants.CloudIdPort)}
}

func (m *cloudidManager) getDeployment(oc *v1alpha1.OnecloudCluster, cfg *v1alpha1.OnecloudClusterConfig) (*apps.Deployment, error) {
cf := func(volMounts []corev1.VolumeMount) []corev1.Container {
return []corev1.Container{
{
Name: "server",
Image: oc.Spec.CloudId.Image,
ImagePullPolicy: oc.Spec.Cloudnet.ImagePullPolicy,
Command: []string{"/opt/yunion/bin/cloudid", "--config", "/etc/yunion/cloudid.conf"},
VolumeMounts: volMounts,
},
}
}
return m.newDefaultDeploymentNoInit(
v1alpha1.CloudIdComponentType, oc,
NewVolumeHelper(oc, controller.ComponentConfigMapName(oc, v1alpha1.CloudIdComponentType), v1alpha1.CloudIdComponentType),
oc.Spec.CloudId, cf)
}

func (m *cloudidManager) getDeploymentStatus(oc *v1alpha1.OnecloudCluster) *v1alpha1.DeploymentStatus {
return &oc.Status.CloudId
}
4 changes: 4 additions & 0 deletions pkg/manager/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -1181,3 +1181,7 @@ func (m *ComponentManager) Itsm() manager.Manager {
func (m *ComponentManager) Telegraf() manager.Manager {
return newTelegrafManager(m)
}

func (m *ComponentManager) CloudId() manager.Manager {
return newCloudIdManager(m)
}

0 comments on commit 525f310

Please sign in to comment.