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

test/k8s: keep configmap across upgrade test #12051

Merged
merged 2 commits into from
Jun 15, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Documentation/cmdref/cilium-operator-generic.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ cilium-operator-generic [flags]
--identity-allocation-mode string Method to use for identity allocation (default "kvstore")
--identity-gc-interval duration GC interval for security identities (default 15m0s)
--identity-heartbeat-timeout duration Timeout after which identity expires on lack of heartbeat (default 30m0s)
--ipam string Backend to use for IPAM (default "cluster-pool")
--ipam string Backend to use for IPAM (default "hostscope-legacy")
--k8s-api-server string Kubernetes API server URL
--k8s-client-burst int Burst value allowed for the K8s client
--k8s-client-qps float32 Queries per second limit for the K8s client
Expand Down
59 changes: 49 additions & 10 deletions Documentation/install/upgrade.rst
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ Kubernetes resources are updated accordingly to version you are upgrading to:
Make sure that you are using the same options as for the initial deployment.
Instead of using ``--set``, you can also modify the ``values.yaml`` in
``install/kubernetes/cilium/values.yaml`` and use it to regenerate the YAML
for the latest version.
for the latest version. Running any of the previous commands will overwrite
the existing cluster's `ConfigMap` which might not be ideal if you want to
keep your existing `ConfigMap`.

Step 2: Option B: Preserve ConfigMap
------------------------------------
Expand Down Expand Up @@ -209,21 +211,16 @@ configuration options for each minor version.

.. group-tab:: Helm

Deploy Cilium release via Helm:

.. parsed-literal::

helm upgrade cilium |CHART_RELEASE| \\
--namespace=kube-system \\
--set config.enabled=false
Keeping an existing `ConfigMap` with ``helm upgrade`` is currently not
supported.

.. note::

The above variant can not be used in combination with ``--set`` or providing
``values.yaml`` because all options are fed into the DaemonSets and
Deployments using the `ConfigMap` which is not generated if
``config.enabled=false`` is set. The above command *only* generates the
DaemonSet, Deployment and RBAC definitions.
``config.enabled=false`` or ``config.keepCurrent=true`` are set. The above
command *only* generates the DaemonSet, Deployment and RBAC definitions.
Comment on lines 221 to +223
Copy link
Member

Choose a reason for hiding this comment

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

Actually we need to drop this hunk.


Step 3: Rolling Back
--------------------
Expand Down Expand Up @@ -328,6 +325,48 @@ IMPORTANT: Changes required before upgrading to 1.8.0
Do not upgrade to 1.8.0 before reading the following section and completing
the required steps.

* The ``cilium-agent`` container ``liveness`` and ``readiness`` probes have been
replaced with a ``httpGet`` instead of an ``exec`` probe. Unfortunately,
upgrading using ``kubectl apply`` does not work since the merge strategy done
by Kubernetes does not remove the old probe when replacing with a new one.
This causes ``kubectl apply`` command to return an error such as:

::

The DaemonSet "cilium" is invalid:
* spec.template.spec.containers[0].livenessProbe.httpGet: Forbidden: may not specify more than 1 handler type
* spec.template.spec.containers[0].readinessProbe.httpGet: Forbidden: may not specify more than 1 handler type

Existing users must either choose to keep the ``exec`` probe in the
`DaemonSet` specification to safely upgrade or re-create the Cilium `DaemonSet`
without the deprecated probe. It is advisable to keep the probe when doing
an upgrade from ``v1.7.x`` to ``v1.8.x`` in the event of having to do a
downgrade. The removal of this probe should be done after a successful
upgrade.

The helm option ``agent.keepDeprecatedProbes=true`` will keep the
``exec`` probe in the new `DaemonSet`:

.. tabs::
.. group-tab:: kubectl

.. parsed-literal::

helm template cilium \
--namespace=kube-system \
...
--set agent.keepDeprecatedProbes=true \
...
> cilium.yaml
kubectl apply -f cilium.yaml

.. group-tab:: Helm

.. parsed-literal::

helm upgrade cilium --namespace=kube-system \
--set agent.keepDeprecatedProbes=true

* **Important:** The masquerading behavior has changed, depending on how you
have configured masquerading you need to take action to avoid potential
NetworkPolicy related drops:
Expand Down
16 changes: 16 additions & 0 deletions install/kubernetes/cilium/charts/agent/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ spec:
command:
- cilium-agent
livenessProbe:
{{- if .Values.keepDeprecatedProbes }}
exec:
command:
- cilium
- status
- --brief
{{- else }}
httpGet:
host: '127.0.0.1'
path: /healthz
Expand All @@ -63,6 +70,7 @@ spec:
httpHeaders:
- name: "brief"
value: "true"
{{- end }}
failureThreshold: 10
# The initial delay for the liveness probe is intentionally large to
# avoid an endless kill & restart cycle if in the event that the initial
Expand All @@ -72,6 +80,13 @@ spec:
successThreshold: 1
timeoutSeconds: 5
readinessProbe:
{{- if .Values.keepDeprecatedProbes }}
exec:
command:
- cilium
- status
- --brief
{{- else }}
httpGet:
host: '127.0.0.1'
path: /healthz
Expand All @@ -80,6 +95,7 @@ spec:
httpHeaders:
- name: "brief"
value: "true"
{{- end }}
failureThreshold: 3
initialDelaySeconds: 5
periodSeconds: 30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ spec:
- cilium-operator-aws
{{- else if .Values.global.azure.enabled }}
- cilium-operator-azure
{{- else }}
{{- else if .Values.global.ipam.operator }}
- cilium-operator-generic
{{- else }}
- cilium-operator
{{- end }}
env:
- name: K8S_NODE_NAME
Expand Down Expand Up @@ -114,8 +116,10 @@ spec:
image: "{{ .Values.global.registry }}/{{ .Values.image }}-aws:{{ .Values.global.tag }}"
{{- else if .Values.global.azure.enabled }}
image: "{{ .Values.global.registry }}/{{ .Values.image }}-azure:{{ .Values.global.tag }}"
{{- else }}
{{- else if .Values.global.ipam.operator }}
image: "{{ .Values.global.registry }}/{{ .Values.image }}-generic:{{ .Values.global.tag }}"
{{- else }}
image: "{{ .Values.global.registry }}/{{ .Values.image }}:{{ .Values.global.tag }}"
{{- end }}
{{- end }}
imagePullPolicy: {{ .Values.global.pullPolicy }}
Expand Down
2 changes: 2 additions & 0 deletions install/kubernetes/cilium/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ agent:
sleepAfterInit: false
# Keep the deprecated selector labels when deploying Cilium DaemonSet
keepDeprecatedLabels: false
# Keep the deprecated probes when deploying Cilium DaemonSet
keepDeprecatedProbes: false

# Include the cilium-config ConfigMap
config:
Expand Down
4 changes: 3 additions & 1 deletion operator/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ func init() {
case "cilium-operator-azure":
defaultIPAM = ipamOption.IPAMAzure
case "cilium-operator-generic":
defaultIPAM = ipamOption.IPAMOperator
// Default to Legacy for upgrade paths; new users should
// explicitly override the IPAM flag.
defaultIPAM = ipamOption.IPAMHostScopeLegacy
}

flags.String(option.IPAM, defaultIPAM, "Backend to use for IPAM")
Expand Down
18 changes: 18 additions & 0 deletions test/helpers/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2355,6 +2355,24 @@ func (kub *Kubectl) RunHelm(action, repo, helmName, version, namespace string, o
"%s", action, helmName, repo, version, namespace, optionsString)), nil
}

// RunHelmTemplate runs the helm template command for a specific version.
func (kub *Kubectl) RunHelmTemplateApply(repo, helmName, version, namespace string, options map[string]string) (*CmdRes, error) {
err := kub.overwriteHelmOptions(options)
if err != nil {
return nil, err
}
optionsString := ""

for k, v := range options {
optionsString += fmt.Sprintf(" --set %s=%s ", k, v)
}

return kub.ExecMiddle(fmt.Sprintf("helm template %s %s "+
"--version=%s "+
"--namespace=%s "+
"%s | %s apply -f -", helmName, repo, version, namespace, optionsString, KubectlCmd)), nil
}

// CiliumUninstall uninstalls Cilium with the provided Helm options.
func (kub *Kubectl) CiliumUninstall(filename string, options map[string]string) error {
return kub.ciliumUninstallHelm(filename, options)
Expand Down
22 changes: 17 additions & 5 deletions test/k8sT/Updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,16 +445,26 @@ func InstallAndValidateCiliumUpgrades(kubectl *helpers.Kubectl, oldHelmChartVers
By("Upgrading Cilium to %s", newHelmChartVersion)
opts = map[string]string{
"global.tag": newImageVersion,
// Do not use new configuration map as we are testing an upgrade
// scenario where the user deploys Cilium while keeping its existing
// configuration map.
"config.enabled": "false",
}
// We have removed the labels since >= 1.7 and we are only testing
// starting from 1.6.
if oldHelmChartVersion == "1.6-dev" {
opts["agent.keepDeprecatedLabels"] = "true"
}
// We have replaced the liveness and readiness probes since >= 1.8 and
// we need to keep those deprecated probes from <1.8-dev to >=1.8
// upgrades since kubernetes does not do `kubectl apply -f` correctly.
switch oldHelmChartVersion {
case "1.6-dev", "1.7-dev":
opts["agent.keepDeprecatedProbes"] = "true"
}

EventuallyWithOffset(1, func() (*helpers.CmdRes, error) {
return kubectl.RunHelm(
"upgrade",
return kubectl.RunHelmTemplateApply(
filepath.Join(kubectl.BasePath(), helpers.HelmTemplate),
"cilium",
newHelmChartVersion,
Expand All @@ -481,9 +491,11 @@ func InstallAndValidateCiliumUpgrades(kubectl *helpers.Kubectl, oldHelmChartVers
checkNoInteruptsInSVCFlows()

By("Downgrading cilium to %s image", oldHelmChartVersion)
// rollback cilium 1 because it's the version that we have started
// cilium with in this updates test.
cmd = kubectl.ExecMiddle("helm rollback cilium 1 --namespace=" + helpers.CiliumNamespace)
// Install the previous configuration using helm. This is a hack
// as we have previously upgrade Cilium using kubectl apply -f.
// helm get keeps the values used when we installed Cilium wihtout the
// upgrade changes that we have done with kubectl apply -f.
cmd = kubectl.ExecMiddle(fmt.Sprintf("helm get -n %s manifest cilium | kubectl apply -f -", helpers.CiliumNamespace))
ExpectWithOffset(1, cmd).To(helpers.CMDSuccess(), "Cilium %q was not able to be deployed", oldHelmChartVersion)

err = helpers.WithTimeout(
Expand Down