Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN GO111MODULE=on CGO_ENABLED=0 go install -ldflags '-w -s' github.com/osrg/gob
FROM alpine
RUN apk add --update ca-certificates iptables && update-ca-certificates
COPY --from=openelb-builder /go/bin/controller /usr/local/bin/openelb-controller
# COPY --from=openelb-builder /go/bin/speaker /usr/local/bin/openelb-speaker
COPY --from=openelb-builder /go/bin/speaker /usr/local/bin/openelb-speaker
# COPY --from=openelb-builder /go/bin/apiserver /usr/local/bin/openelb-apiserver
COPY --from=openelb-builder /go/bin/gobgp /usr/local/bin/gobgp

Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha2/eip_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ func (e Eip) ValidateCreate() (admission.Warnings, error) {
return nil, err
}

if e.Spec.Protocol == constant.OpenELBProtocolLayer2 && e.Spec.Interface == "" {
return nil, fmt.Errorf("if protocol is layer2, interface should not be empty")
if (e.Spec.Protocol == constant.OpenELBProtocolLayer2 || e.Spec.Protocol == constant.OpenELBProtocolVip) && e.Spec.Interface == "" {
return nil, fmt.Errorf("if protocol is layer2 or vip, interface should not be empty")
}
return nil, e.validate(true)
}
Expand Down Expand Up @@ -267,8 +267,8 @@ func (e Eip) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
}
}

if e.Spec.Protocol == constant.OpenELBProtocolLayer2 && e.Spec.Interface == "" {
return nil, fmt.Errorf("if protocol is layer2, interface should not be empty")
if (e.Spec.Protocol == constant.OpenELBProtocolLayer2 || e.Spec.Protocol == constant.OpenELBProtocolVip) && e.Spec.Interface == "" {
return nil, fmt.Errorf("if protocol is layer2 or vip, interface should not be empty")
}

return nil, nil
Expand Down
2 changes: 1 addition & 1 deletion build/forward/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

FROM alpine
WORKDIR /
COPY images/forward/entry-point.sh /entry-point.sh
COPY build/forward/entry-point.sh /entry-point.sh
RUN apk update && apk add iptables && \
chmod +x /entry-point.sh
CMD [ "/entry-point.sh" ]
2 changes: 1 addition & 1 deletion build/proxy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

FROM alpine
WORKDIR /
COPY images/proxy/entry-point.sh /entry-point.sh
COPY build/proxy/entry-point.sh /entry-point.sh
RUN apk update && apk add iptables && \
chmod +x /entry-point.sh
CMD [ "/entry-point.sh" ]
4 changes: 3 additions & 1 deletion build/speaker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ ADD . /workspace/

RUN make speaker
RUN mv /workspace/bin/cmd/speaker ${OUTDIR}/usr/local/bin/openelb-speaker

RUN GO111MODULE=on CGO_ENABLED=0 go install -ldflags '-w -s' github.com/osrg/gobgp/cmd/gobgp
RUN mv /go/bin/gobgp ${OUTDIR}/usr/local/bin/gobgp

Expand All @@ -19,7 +18,10 @@ RUN mv /go/bin/gobgp ${OUTDIR}/usr/local/bin/gobgp
#############
FROM alpine

RUN apk add --update --no-cache keepalived
COPY --from=build_context /out/ /
ADD build/speaker/keepalived.tmpl /
ADD build/speaker/keepalived-check.sh /
WORKDIR /

ENTRYPOINT ["openelb-speaker"]
Expand Down
11 changes: 11 additions & 0 deletions build/speaker/keepalived-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

TYPE="$1"
NAME="$2"
STATE="$3"

dir_path="/var/run/keepalived/state"
mkdir -p "$dir_path" 2>/dev/null

echo -n "${STATE}" > $dir_path/${NAME}
exit 0
33 changes: 33 additions & 0 deletions build/speaker/keepalived.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
global_defs {
vrrp_version 3
script_user root
enable_script_security
router_id {{ .name }}
}


#Check if the VIP list is empty

{{ range $name, $instance := .instances }}
{{ if $instance.Enabled }}
vrrp_instance {{ $name }} {
state BACKUP
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one question: Why is there a fixed value BACKUP here? When will it become MASTER?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's what the official documentation says:
Initial state, MASTER|BACKUP If the priority is 255, then the instance will transition immediately to MASTER if state MASTER is specified; otherwise the instance will wait between 3 and 4 advert intervals before it can transition, depending on the priority.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.

interface {{ $instance.Iface }}
virtual_router_id {{ $instance.RouteID }}
priority {{ $instance.Priority }}
nopreempt
advert_int 1

track_interface {
{{ $instance.Iface }}
}

virtual_ipaddress { {{ range $instance.Svcips }}
{{ . }}{{ end }}
}

notify /keepalived-check.sh
}

{{ end }}
{{ end }}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.0
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.12.1
name: bgpconfs.network.kubesphere.io
spec:
group: network.kubesphere.io
Expand Down Expand Up @@ -135,6 +133,8 @@ spec:
listenPort:
format: int32
type: integer
policy:
type: string
routerId:
type: string
useMultiplePaths:
Expand All @@ -159,9 +159,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.0
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.12.1
name: bgppeers.network.kubesphere.io
spec:
group: network.kubesphere.io
Expand Down Expand Up @@ -266,6 +264,7 @@ spec:
are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
timers:
properties:
config:
Expand Down Expand Up @@ -425,9 +424,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.0
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.12.1
name: eips.network.kubesphere.io
spec:
group: network.kubesphere.io
Expand Down Expand Up @@ -113,6 +111,19 @@ spec:
type: boolean
interface:
type: string
namespaceSelector:
additionalProperties:
type: string
description: specify the namespace for allocation by selector
type: object
namespaces:
description: specify the namespace for the allocation by name
items:
type: string
type: array
priority:
description: priority for automatically assigning addresses
type: integer
protocol:
enum:
- bgp
Expand Down Expand Up @@ -151,9 +162,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
49 changes: 0 additions & 49 deletions charts/templates/openelb-speaker-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,52 +115,3 @@ kind: ServiceAccount
metadata:
name: {{ template "openelb.speaker.serviceAccountName" . }}
namespace: {{ template "openelb.namespace" . }}



# kube-keepalived-vip
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
{{- include "openelb.keepalived.labels" . | nindent 4 }}
name: {{ template "openelb.keepalived.fullname" . }}
rules:
- apiGroups:
- ""
resources:
- pods
- nodes
- endpoints
- services
- configmaps
verbs:
- get
- list
- watch

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
{{- include "openelb.keepalived.labels" . | nindent 4 }}
name: {{ template "openelb.keepalived.fullname" . }}
subjects:
- kind: ServiceAccount
name: kube-keepalived-vip
namespace: {{ template "openelb.namespace" . }}
roleRef:
kind: ClusterRole
name: {{ template "openelb.keepalived.fullname" . }}
apiGroup: rbac.authorization.k8s.io

---
apiVersion: v1
kind: ServiceAccount
metadata:
name: kube-keepalived-vip
namespace: {{ template "openelb.namespace" . }}
labels:
{{- include "openelb.keepalived.labels" . | nindent 4 }}
1 change: 0 additions & 1 deletion charts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,5 @@ speaker:

customImage:
enable: true
vipImage: "" # "kubesphere/kube-keepalived-vip:0.35"
forwardImage: "" # kubesphere/openelb-forward:master
proxyImage: "" # kubesphere/openelb-proxy:master
22 changes: 5 additions & 17 deletions cmd/speaker/app/speaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
bgpd "github.com/openelb/openelb/pkg/speaker/bgp/bgp"
"github.com/openelb/openelb/pkg/speaker/layer2"
"github.com/openelb/openelb/pkg/speaker/vip"
"github.com/openelb/openelb/pkg/util"
"github.com/openelb/openelb/pkg/version"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -97,7 +96,7 @@ func Run(opt *options.OpenELBSpeakerOptions) error {
return err
}

spmanager := speaker.NewSpeakerManager(mgr.GetClient())
spmanager := speaker.NewSpeakerManager(mgr.GetClient(), mgr.GetEventRecorderFor("speakerManager"))

//For gobgp
bgpServer := bgpd.NewGoBgpd(opt.Bgp)
Expand All @@ -119,26 +118,15 @@ func Run(opt *options.OpenELBSpeakerOptions) error {
//For keepalive
k8sClient := clientset.NewForConfigOrDie(ctrl.GetConfigOrDie())
if opt.Vip.EnableVIP {
ns := util.EnvNamespace()
config := constant.OpenELBVipConfigMap
if opt.Vip.ConfigNamespace != "" {
ns = opt.Vip.ConfigNamespace
}
if opt.Vip.ConfigName != "" {
config = opt.Vip.ConfigName
keepalive, err := vip.NewKeepAlived(k8sClient, opt.Vip.LogPath, opt.Vip.KeepAlivedArgs)
if err != nil {
setupLog.Error(err, "unable to new vip speaker")
return err
}
keepalive := vip.NewKeepAlived(k8sClient, &vip.KeepAlivedConfig{
Args: []string{
fmt.Sprintf("--services-configmap=%s/%s", ns, config),
fmt.Sprintf("--http-port=%d", opt.Vip.HealthPort)},
})

if err := spmanager.RegisterSpeaker(constant.OpenELBProtocolVip, keepalive); err != nil {
setupLog.Error(err, "unable to register keepalive speaker")
return err
}
} else {
vip.Clean(k8sClient)
}

// for layer2 mode
Expand Down
21 changes: 0 additions & 21 deletions config/rbac/role.yaml

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

20 changes: 1 addition & 19 deletions config/rbac/role_binding.yaml

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

Loading