Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #489: add service repo #490

Open
wants to merge 1 commit into
base: release/3.7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require (
k8s.io/apiextensions-apiserver v0.0.0
k8s.io/apimachinery v0.19.3
k8s.io/client-go v9.0.0+incompatible
k8s.io/code-generator v0.15.13-beta.0 // indirect
k8s.io/klog v0.3.3
k8s.io/kube-openapi v0.0.0-20190603182131-db7b694dc208 // indirect
k8s.io/kubernetes v0.0.0-00010101000000-000000000000
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCc
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180524181706-dfa909b99c79/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -856,6 +857,7 @@ golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200417140056-c07e33ef3290/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200515220128-d3bf790afa53 h1:vmsb6v0zUdmUlXfwKaYrHPPRCV0lHq/IwNIf0ASGjyQ=
golang.org/x/tools v0.0.0-20200515220128-d3bf790afa53/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down Expand Up @@ -974,12 +976,14 @@ k8s.io/client-go v0.0.0-20190620085101-78d2af792bab/go.mod h1:E95RaSlHr79aHaX0aG
k8s.io/cloud-provider v0.0.0-20190620090043-8301c0bda1f0/go.mod h1:UXU55LeVTrjyQNw86sHjagiYhSZjYxWKXvx0Ml17KvM=
k8s.io/cluster-bootstrap v0.0.0-20190620090013-c9a0fc045dc1 h1:cErkOWdXBPUiD1iqyj6Zwnxvcy2GG+M3CNoetJRlbyE=
k8s.io/cluster-bootstrap v0.0.0-20190620090013-c9a0fc045dc1/go.mod h1:cCRw3eZzlJdySYRtkL/N4cAClxYCzyrBL3V8cblTlUo=
k8s.io/code-generator v0.0.0-20190612205613-18da4a14b22b h1:p+PRuwXWwk5e+UYvicGiavEupapqM5NOxUl3y1GkD6c=
k8s.io/code-generator v0.0.0-20190612205613-18da4a14b22b/go.mod h1:G8bQwmHm2eafm5bgtX67XDZQ8CWKSGu9DekI+yN4Y5I=
k8s.io/component-base v0.0.0-20190620085130-185d68e6e6ea h1:CAN9Jo6bb5+mp3s1/1w8TbaWIxYK1WGQwwYvlacSet4=
k8s.io/component-base v0.0.0-20190620085130-185d68e6e6ea/go.mod h1:VLedAFwENz2swOjm0zmUXpAP2mV55c49xgaOzPBI/QQ=
k8s.io/cri-api v0.0.0-20190531030430-6117653b35f1/go.mod h1:K6Ux7uDbzKhacgqW0OJg3rjXk/SR9kprCPfSUDXGB5A=
k8s.io/csi-translation-lib v0.0.0-20190620090116-299a7b270edc/go.mod h1:L51Xd2IwQCsOBx41c4YZR9dY1h1IjMk8r3Nnv3L80KM=
k8s.io/gengo v0.0.0-20190116091435-f8a0810f38af/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6 h1:4s3/R4+OYYYUKptXPhZKjQ04WJ6EhQQVFdjOFvCazDk=
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/heapster v1.2.0-beta.1/go.mod h1:h1uhptVXMwC8xtZBYsPXKVi8fpdlYkTs6k949KozGrM=
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ const (
DevtoolDB = "devtool"
DevtoolDBUser = "devtool"

ServiceNameRepo = "repo"
ServiceTypeRepo = "repo"
RepoPort = 30998

ServiceNameMeter = "meter"
ServiceTypeMeter = "meter"
MeterPort = 30909
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/onecloud/v1alpha1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func SetDefaults_OnecloudClusterSpec(obj *OnecloudClusterSpec, isEE bool) {
CloudIdComponentType: &obj.CloudId,
SuggestionComponentType: &obj.Suggestion,
CloudmonComponentType: &obj.Cloudmon.DeploymentSpec,
RepoComponentType: &obj.Repo,
} {
SetDefaults_DeploymentSpec(spec, getImage(obj.ImageRepository, spec.Repository, cType, spec.ImageName, obj.Version, spec.Tag))
}
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 @@ -128,6 +128,8 @@ const (
CloudIdComponentType ComponentType = "cloudid"

SuggestionComponentType ComponentType = "suggestion"

RepoComponentType ComponentType = "repo"
)

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

// MonitorStack holds configuration for grafana, loki, prometheus and thanos services
MonitorStack MonitorStackSpec `json:"monitorStack"`

// Influxdb holds configuration for influxdb
Repo DeploymentSpec `json:"repo"`
}

// OnecloudClusterStatus describes cluster status
Expand Down Expand Up @@ -300,6 +305,7 @@ type OnecloudClusterStatus struct {
Itsm DeploymentStatus `json:"itsm,omitempty"`
CloudId DeploymentStatus `json:"cloudid,omitempty"`
MonitorStack MonitorStackStatus `json:"monitorStack,omitempty"`
Repo DeploymentStatus `json:"repo,omitempty"`
}

type EtcdClusterSpec struct {
Expand Down
3 changes: 2 additions & 1 deletion 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.

1 change: 0 additions & 1 deletion pkg/apis/onecloud/v1alpha1/zz_generated.defaults.go

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

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 @@ -138,6 +138,7 @@ func (occ *defaultClusterControl) updateOnecloudCluster(oc *v1alpha1.OnecloudClu
components.CloudId(),
components.Cloudmon(),
components.Suggestion(),
components.Repo(),
}
var grp errgroup.Group
for _, component := range dependComponents {
Expand Down
22 changes: 21 additions & 1 deletion pkg/controller/onecloud_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@ type registerEndpointComponent struct {
serviceType string
port int
prefix string
enableSSL bool
}

func NewRegisterEndpointComponent(
Expand All @@ -888,11 +889,30 @@ func NewRegisterEndpointComponent(
serviceType: serviceType,
port: port,
prefix: prefix,
enableSSL: true,
}
}

func NewRegisterEndpointComponentWithSsl(
man ComponentManager,
ctype v1alpha1.ComponentType,
serviceName string,
serviceType string,
port int, prefix string, enableSSL bool,
) PhaseControl {
return &registerEndpointComponent{
baseComponent: newBaseComponent(man),
cType: ctype,
serviceName: serviceName,
serviceType: serviceType,
port: port,
prefix: prefix,
enableSSL: enableSSL,
}
}

func (c *registerEndpointComponent) Setup() error {
return c.RegisterCloudServiceEndpoint(c.cType, c.serviceName, c.serviceType, c.port, c.prefix, true)
return c.RegisterCloudServiceEndpoint(c.cType, c.serviceName, c.serviceType, c.port, c.prefix, c.enableSSL)
}

type itsmComponent struct {
Expand Down
4 changes: 4 additions & 0 deletions pkg/manager/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,10 @@ func (m *ComponentManager) Notify() manager.Manager {
return newNotifyManager(m)
}

func (m *ComponentManager) Repo() manager.Manager {
return newRepoManager(m)
}

func (m *ComponentManager) Baremetal() manager.Manager {
return newBaremetalManager(m)
}
Expand Down
139 changes: 139 additions & 0 deletions pkg/manager/component/repo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package component

import (
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"
)

const (
RepoConfigTemplate = `
server {
listen {{ .Port }};
server_name localhost;

#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
autoindex on;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
`
)

type RepoConfig struct {
Port int
}

func (c RepoConfig) GetContent() (string, error) {
return CompileTemplateFromMap(RepoConfigTemplate, c)
}

type repoManager struct {
*ComponentManager
}

func newRepoManager(man *ComponentManager) manager.Manager {
return &repoManager{man}
}

func (r *repoManager) Sync(oc *v1alpha1.OnecloudCluster) error {
return syncComponent(r, oc, oc.Spec.Repo.Disable, "")
}

func (r *repoManager) getPhaseControl(man controller.ComponentManager, zone string) controller.PhaseControl {
return controller.NewRegisterEndpointComponentWithSsl(
man, v1alpha1.RepoComponentType,

constants.ServiceNameRepo, constants.ServiceTypeRepo,
constants.RepoPort, "", false,
)
}

func (r *repoManager) getService(oc *v1alpha1.OnecloudCluster, zone string) []*corev1.Service {
return []*corev1.Service{r.newSingleNodePortService(v1alpha1.RepoComponentType, oc, constants.RepoPort)}
}

func (r *repoManager) getConfigMap(oc *v1alpha1.OnecloudCluster, cfg *v1alpha1.OnecloudClusterConfig, zone string) (*corev1.ConfigMap, bool, error) {
config := RepoConfig{
Port: constants.RepoPort,
}
content, err := config.GetContent()
if err != nil {
return nil, false, err
}
return r.newConfigMap(v1alpha1.RepoComponentType, "", oc, content), false, nil
}

func (r *repoManager) getDeployment(oc *v1alpha1.OnecloudCluster, cfg *v1alpha1.OnecloudClusterConfig, zone string) (*apps.Deployment, error) {
cfgMapname := controller.ComponentConfigMapName(oc, v1alpha1.RepoComponentType)
pluginCfgVol := corev1.Volume{
Name: constants.ServiceNameRepo,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: cfgMapname,
},
Items: []corev1.KeyToPath{
{Key: "config", Path: "default.conf"},
},
},
},
}
deploy, err := m.newCloudServiceSinglePortDeployment(v1alpha1.RepoComponentType, "", oc, &oc.Spec.Repo, constants.RepoPort, false, false)
if err != nil {
return nil, err
}
spec := &deploy.Spec.Template.Spec
spec.Containers[0].Command = nil
spec.Containers[0].VolumeMounts = append(spec.Containers[0].VolumeMounts,
corev1.VolumeMount{
MountPath: "/etc/nginx/conf.d",
Name: constants.ServiceNameRepo,
})
spec.Volumes = append(spec.Volumes, pluginCfgVol)
return deploy, nil
}

func (r *repoManager) getDeploymentStatus(oc *v1alpha1.OnecloudCluster, zone string) *v1alpha1.DeploymentStatus {
return &oc.Status.Repo
}