Skip to content
Closed
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
101 changes: 5 additions & 96 deletions pkg/controller/template/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ type RenderConfig struct {
}

const (
filesDir = "files"
unitsDir = "units"
platformBase = "_base"
platformOnPrem = "on-prem"
filesDir = "files"
unitsDir = "units"
platformBase = "_base"
)

// generateTemplateMachineConfigs returns MachineConfig objects from the templateDir and a config object
Expand Down Expand Up @@ -193,10 +192,7 @@ func generateMachineConfigForName(config *RenderConfig, role, name, templateDir,
platformDirs := []string{}
if !*commonAdded {
// Loop over templates/common which applies everywhere
for _, dir := range []string{platformBase, platformOnPrem, platformString} {
if dir == platformOnPrem && !onPremPlatform(config.Infra.Status.PlatformStatus.Type) {
continue
}
for _, dir := range []string{platformBase, platformString} {
basePath := filepath.Join(templateDir, "common", dir)
exists, err := existsDir(basePath)
if err != nil {
Expand All @@ -209,12 +205,8 @@ func generateMachineConfigForName(config *RenderConfig, role, name, templateDir,
}
*commonAdded = true
}

// And now over the target e.g. templates/master/00-master,01-master-container-runtime,01-master-kubelet
for _, dir := range []string{platformBase, platformOnPrem, platformString} {
if dir == platformOnPrem && !onPremPlatform(config.Infra.Status.PlatformStatus.Type) {
continue
}
for _, dir := range []string{platformBase, platformString} {
platformPath := filepath.Join(path, dir)
exists, err := existsDir(platformPath)
if err != nil {
Expand Down Expand Up @@ -291,10 +283,6 @@ func renderTemplate(config RenderConfig, path string, b []byte) ([]byte, error)
funcs["skip"] = skipMissing
funcs["cloudProvider"] = cloudProvider
funcs["cloudConfigFlag"] = cloudConfigFlag
funcs["onPremPlatformAPIServerInternalIP"] = onPremPlatformAPIServerInternalIP
funcs["onPremPlatformIngressIP"] = onPremPlatformIngressIP
funcs["onPremPlatformShortName"] = onPremPlatformShortName
funcs["onPremPlatformKeepalivedEnableUnicast"] = onPremPlatformKeepalivedEnableUnicast
tmpl, err := template.New(path).Funcs(funcs).Parse(string(b))
if err != nil {
return nil, fmt.Errorf("failed to parse template %s: %v", path, err)
Expand Down Expand Up @@ -368,76 +356,6 @@ func cloudConfigFlag(cfg RenderConfig) interface{} {
}
}

func onPremPlatformShortName(cfg RenderConfig) interface{} {
if cfg.Infra.Status.PlatformStatus != nil {
switch cfg.Infra.Status.PlatformStatus.Type {
case configv1.BareMetalPlatformType:
return "kni"
case configv1.OvirtPlatformType:
return "ovirt"
case configv1.OpenStackPlatformType:
return "openstack"
case configv1.VSpherePlatformType:
return "vsphere"
default:
return ""
}
} else {
return ""
}
}

func onPremPlatformKeepalivedEnableUnicast(cfg RenderConfig) (interface{}, error) {
if cfg.Infra.Status.PlatformStatus != nil {
switch cfg.Infra.Status.PlatformStatus.Type {
case configv1.BareMetalPlatformType:
return "yes", nil
default:
return "no", nil
}
} else {
return "no", nil
}
}

func onPremPlatformIngressIP(cfg RenderConfig) (interface{}, error) {
if cfg.Infra.Status.PlatformStatus != nil {
switch cfg.Infra.Status.PlatformStatus.Type {
case configv1.BareMetalPlatformType:
return cfg.Infra.Status.PlatformStatus.BareMetal.IngressIP, nil
case configv1.OvirtPlatformType:
return cfg.Infra.Status.PlatformStatus.Ovirt.IngressIP, nil
case configv1.OpenStackPlatformType:
return cfg.Infra.Status.PlatformStatus.OpenStack.IngressIP, nil
case configv1.VSpherePlatformType:
return cfg.Infra.Status.PlatformStatus.VSphere.IngressIP, nil
default:
return nil, fmt.Errorf("invalid platform for Ingress IP")
}
} else {
return nil, fmt.Errorf("")
}
}

func onPremPlatformAPIServerInternalIP(cfg RenderConfig) (interface{}, error) {
if cfg.Infra.Status.PlatformStatus != nil {
switch cfg.Infra.Status.PlatformStatus.Type {
case configv1.BareMetalPlatformType:
return cfg.Infra.Status.PlatformStatus.BareMetal.APIServerInternalIP, nil
case configv1.OvirtPlatformType:
return cfg.Infra.Status.PlatformStatus.Ovirt.APIServerInternalIP, nil
case configv1.OpenStackPlatformType:
return cfg.Infra.Status.PlatformStatus.OpenStack.APIServerInternalIP, nil
case configv1.VSpherePlatformType:
return cfg.Infra.Status.PlatformStatus.VSphere.APIServerInternalIP, nil
default:
return nil, fmt.Errorf("invalid platform for API Server Internal IP")
}
} else {
return nil, fmt.Errorf("")
}
}

// existsDir returns true if path exists and is a directory, false if the path
// does not exist, and error if there is a runtime error or the path is not a directory
func existsDir(path string) (bool, error) {
Expand All @@ -453,12 +371,3 @@ func existsDir(path string) (bool, error) {
}
return true, nil
}

func onPremPlatform(platformString configv1.PlatformType) bool {
switch platformString {
case configv1.BareMetalPlatformType, configv1.OvirtPlatformType, configv1.OpenStackPlatformType, configv1.VSpherePlatformType:
return true
default:
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ contents:
{{ .Images.baremetalRuntimeCfgImage }} \
node-ip \
show \
"{{ onPremPlatformAPIServerInternalIP . }}" \
"{{ onPremPlatformIngressIP . }}")
"{{.Infra.Status.PlatformStatus.BareMetal.APIServerInternalIP}}" \
"{{.Infra.Status.PlatformStatus.BareMetal.IngressIP}}")
DOMAIN="{{.DNS.Spec.BaseDomain}}"
if [[ -n "$NAMESERVER_IP" ]]; then
>&2 echo "NM resolv-prepender: Prepending 'nameserver $NAMESERVER_IP' to /etc/resolv.conf (other nameservers from /var/run/NetworkManager/resolv.conf)"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mode: 0644
path: "/etc/NetworkManager/conf.d/99-{{ onPremPlatformShortName . }}.conf"
path: "/etc/NetworkManager/conf.d/99-kni.conf"
contents:
inline: |
[main]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ contents:
reload
template IN {{`{{ .Cluster.IngressVIPRecordType }}`}} {{ .DNS.Spec.BaseDomain }} {
match .*.apps.{{ .DNS.Spec.BaseDomain }}
answer "{{`{{"{{ .Name }}"}}`}} 60 in {{`{{"{{ .Type }}"}}`}} {{ onPremPlatformIngressIP . }}"
answer "{{`{{"{{ .Name }}"}}`}} 60 in {{`{{"{{ .Type }}"}}`}} {{ .Infra.Status.PlatformStatus.BareMetal.IngressIP }}"
fallthrough
}
template IN {{`{{ .Cluster.IngressVIPEmptyType }}`}} {{ .DNS.Spec.BaseDomain }} {
Expand All @@ -20,7 +20,7 @@ contents:
}
template IN {{`{{ .Cluster.APIVIPRecordType }}`}} {{ .DNS.Spec.BaseDomain }} {
match api.{{ .DNS.Spec.BaseDomain }}
answer "{{`{{"{{ .Name }}"}}`}} 60 in {{`{{"{{ .Type }}"}}`}} {{ onPremPlatformAPIServerInternalIP . }}"
answer "{{`{{"{{ .Name }}"}}`}} 60 in {{`{{"{{ .Type }}"}}`}} {{ .Infra.Status.PlatformStatus.BareMetal.APIServerInternalIP }}"
fallthrough
}
template IN {{`{{ .Cluster.APIVIPEmptyType }}`}} {{ .DNS.Spec.BaseDomain }} {
Expand All @@ -29,7 +29,7 @@ contents:
}
template IN {{`{{ .Cluster.APIVIPRecordType }}`}} {{ .DNS.Spec.BaseDomain }} {
match api-int.{{ .DNS.Spec.BaseDomain }}
answer "{{`{{"{{ .Name }}"}}`}} 60 in {{`{{"{{ .Type }}"}}`}} {{ onPremPlatformAPIServerInternalIP . }}"
answer "{{`{{"{{ .Name }}"}}`}} 60 in {{`{{"{{ .Type }}"}}`}} {{ .Infra.Status.PlatformStatus.BareMetal.APIServerInternalIP }}"
fallthrough
}
template IN {{`{{ .Cluster.APIVIPEmptyType }}`}} {{ .DNS.Spec.BaseDomain }} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ contents:
apiVersion: v1
metadata:
name: coredns
namespace: openshift-{{ onPremPlatformShortName . }}-infra
namespace: openshift-kni-infra
creationTimestamp:
deletionGracePeriodSeconds: 65
labels:
app: {{ onPremPlatformShortName . }}-infra-mdns
app: kni-infra-mdns
spec:
volumes:
- name: resource-dir
Expand All @@ -33,9 +33,9 @@ contents:
- render
- "/etc/kubernetes/kubeconfig"
- "--api-vip"
- "{{ onPremPlatformAPIServerInternalIP . }}"
- "{{ .Infra.Status.PlatformStatus.BareMetal.APIServerInternalIP }}"
- "--ingress-vip"
- "{{ onPremPlatformIngressIP . }}"
- "{{ .Infra.Status.PlatformStatus.BareMetal.IngressIP }}"
- "/config"
- "--out-dir"
- "/etc/coredns"
Expand Down Expand Up @@ -94,9 +94,9 @@ contents:
- "/config/Corefile.tmpl"
- "/etc/coredns/Corefile"
- "--api-vip"
- "{{ onPremPlatformAPIServerInternalIP . }}"
- "{{ .Infra.Status.PlatformStatus.BareMetal.APIServerInternalIP }}"
- "--ingress-vip"
- "{{ onPremPlatformIngressIP . }}"
- "{{ .Infra.Status.PlatformStatus.BareMetal.IngressIP }}"
resources:
requests:
cpu: 100m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ contents:
apiVersion: v1
metadata:
name: keepalived
namespace: openshift-{{ onPremPlatformShortName . }}-infra
namespace: openshift-kni-infra
creationTimestamp:
deletionGracePeriodSeconds: 65
labels:
app: {{ onPremPlatformShortName . }}-infra-vrrp
app: kni-infra-vrrp
spec:
volumes:
- name: resource-dir
Expand Down Expand Up @@ -41,9 +41,9 @@ contents:
- render
- "/etc/kubernetes/kubeconfig"
- "--api-vip"
- "{{ onPremPlatformAPIServerInternalIP . }}"
- "{{ .Infra.Status.PlatformStatus.BareMetal.APIServerInternalIP }}"
- "--ingress-vip"
- "{{ onPremPlatformIngressIP . }}"
- "{{ .Infra.Status.PlatformStatus.BareMetal.IngressIP }}"
- "/config"
- "--out-dir"
- "/etc/keepalived"
Expand Down Expand Up @@ -124,7 +124,7 @@ contents:
image: {{ .Images.baremetalRuntimeCfgImage }}
env:
- name: ENABLE_UNICAST
value: "{{ onPremPlatformKeepalivedEnableUnicast . }}"
value: "yes"
- name: IS_BOOTSTRAP
value: "no"
command:
Expand All @@ -133,9 +133,9 @@ contents:
- "/config/keepalived.conf.tmpl"
- "/etc/keepalived/keepalived.conf"
- "--api-vip"
- "{{ onPremPlatformAPIServerInternalIP . }}"
- "{{ .Infra.Status.PlatformStatus.BareMetal.APIServerInternalIP }}"
- "--ingress-vip"
- "{{ onPremPlatformIngressIP . }}"
- "{{ .Infra.Status.PlatformStatus.BareMetal.IngressIP }}"
resources:
requests:
cpu: 100m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ contents:
apiVersion: v1
metadata:
name: mdns-publisher
namespace: openshift-{{ onPremPlatformShortName . }}-infra
namespace: openshift-kni-infra
creationTimestamp:
deletionGracePeriodSeconds: 65
labels:
app: {{ onPremPlatformShortName . }}-infra-mdns
app: kni-infra-mdns
spec:
volumes:
- name: resource-dir
Expand Down Expand Up @@ -60,9 +60,9 @@ contents:
- render
- "/etc/kubernetes/kubeconfig"
- "--api-vip"
- "{{ onPremPlatformAPIServerInternalIP . }}"
- "{{ .Infra.Status.PlatformStatus.BareMetal.APIServerInternalIP }}"
- "--ingress-vip"
- "{{ onPremPlatformIngressIP . }}"
- "{{ .Infra.Status.PlatformStatus.BareMetal.IngressIP }}"
- "/config"
- "--out-dir"
- "/etc/mdns"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contents: |
{{ .Images.baremetalRuntimeCfgImage }} \
node-ip \
set --retry-on-failure \
{{ onPremPlatformAPIServerInternalIP . }}; \
{{.Infra.Status.PlatformStatus.BareMetal.APIServerInternalIP }}; \
do \
sleep 5; \
done"
Expand Down
21 changes: 21 additions & 0 deletions templates/common/openstack/files/NetworkManager-mdns-hostname.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
mode: 0755
path: "/etc/NetworkManager/dispatcher.d/40-mdns-hostname"
contents:
inline: |
#!/bin/bash
STATUS=$2
case "$STATUS" in
up|down|dhcp4-change|dhcp6-change|hostname)
logger -s "NM mdns-hostname triggered by ${2}."
set +e
t_hostname=$(hostname)
if [ -z "${t_hostname}" ]; then
t_hostname="localhost"
fi
mkdir -p /etc/mdns
echo "${t_hostname}">/etc/mdns/hostname
logger -s "Hostname changed: ${t_hostname}"
;;
*)
;;
esac
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
mode: 0755
path: "/etc/NetworkManager/dispatcher.d/30-resolv-prepender"
contents:
inline: |
#!/bin/bash
set -eo pipefail
IFACE=$1
STATUS=$2

{{if .Proxy -}}
{{if .Proxy.HTTPProxy -}}
HTTP_PROXY={{.Proxy.HTTPProxy}}
{{end -}}
{{if .Proxy.HTTPSProxy -}}
HTTPS_PROXY={{.Proxy.HTTPSProxy}}
{{end -}}
{{if .Proxy.NoProxy -}}
NO_PROXY={{.Proxy.NoProxy}}
{{end -}}
{{end -}}

case "$STATUS" in
up|down|dhcp4-change|dhcp6-change)
logger -s "NM resolv-prepender triggered by ${1} ${2}."

# Ensure resolv.conf exists before we try to run podman
if [[ ! -e /etc/resolv.conf ]] || ! grep -q nameserver /etc/resolv.conf; then
cp /var/run/NetworkManager/resolv.conf /etc/resolv.conf
fi

NAMESERVER_IP=$(/usr/bin/podman run --rm \
--authfile /var/lib/kubelet/config.json \
--net=host \
{{ .Images.baremetalRuntimeCfgImage }} \
node-ip \
show \
"{{.Infra.Status.PlatformStatus.OpenStack.APIServerInternalIP}}" \
"{{.Infra.Status.PlatformStatus.OpenStack.IngressIP}}")
DOMAIN="{{.DNS.Spec.BaseDomain}}"
if [[ -n "$NAMESERVER_IP" ]]; then
logger -s "NM resolv-prepender: Prepending 'nameserver $NAMESERVER_IP' to /etc/resolv.conf (other nameservers from /var/run/NetworkManager/resolv.conf)"
sed -e "/^search/d" \
-e "/Generated by/c# Generated by OpenStack resolv prepender NM dispatcher script\nsearch $DOMAIN\nnameserver $NAMESERVER_IP" \
/var/run/NetworkManager/resolv.conf > /etc/resolv.tmp
fi
# Only leave the first 3 nameservers in /etc/resolv.conf
sed -i ':a $!{N; ba}; s/\(^\|\n\)nameserver/\n# nameserver/4g' /etc/resolv.tmp
mv -f /etc/resolv.tmp /etc/resolv.conf
;;
*)
;;
esac
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mode: 0644
path: "/etc/NetworkManager/conf.d/99-openstack.conf"
contents:
inline: |
[main]
rc-manager=unmanaged
[connection]
ipv6.dhcp-duid=ll
ipv6.dhcp-iaid=mac
Loading