Skip to content

Commit

Permalink
test: add tests for cilium pre-flight daemonset
Browse files Browse the repository at this point in the history
Signed-off-by: André Martins <andre@cilium.io>
  • Loading branch information
aanm authored and tgraf committed Nov 6, 2018
1 parent c5c7c8a commit fc7eeef
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 43 deletions.
6 changes: 6 additions & 0 deletions test/helpers/cons.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ var (
// CiliumDefaultDSPatch is the default Cilium DaemonSet patch to be used in all tests.
const CiliumDefaultDSPatch = "cilium-ds-patch.yaml"

// CiliumDefaultPreFlightPatch is the default Cilium Pre-flight DaemonSet patch to be used in all tests.
const CiliumDefaultPreFlightPatch = "cilium-pre-flight-patch.yaml"

// CiliumDefaultPreFlight is the default Cilium Pre-flight DaemonSet descriptor to be used in all tests.
const CiliumDefaultPreFlight = "cilium-pre-flight.yaml"

// CiliumConfigMapPatch is the default Cilium ConfigMap patch to be used in all tests.
const CiliumConfigMapPatch = "cilium-cm-patch.yaml"

Expand Down
101 changes: 58 additions & 43 deletions test/helpers/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,49 @@ func (kub *Kubectl) WaitCleanAllTerminatingPods(timeout int64) error {
return err
}

// DeployPatch deploys the original kubernetes descriptor with the given patch.
func (kub *Kubectl) DeployPatch(original, patch string) error {
// debugYaml only dumps the full created yaml file to the test output if
// the cilium manifest can not be created correctly.
debugYaml := func(original, patch string) {
// dry-run is only available since k8s 1.11
switch GetCurrentK8SEnv() {
case "1.8", "1.9", "1.10":
_ = kub.Exec(fmt.Sprintf(
`%s patch --filename='%s' --patch "$(cat '%s')" --local -o yaml`,
KubectlCmd, original, patch))
default:
_ = kub.Exec(fmt.Sprintf(
`%s patch --filename='%s' --patch "$(cat '%s')" --local --dry-run -o yaml`,
KubectlCmd, original, patch))
}
}

var res *CmdRes
// validation 1st
// dry-run is only available since k8s 1.11
switch GetCurrentK8SEnv() {
case "1.8", "1.9", "1.10":
default:
res = kub.Exec(fmt.Sprintf(
`%s patch --filename='%s' --patch "$(cat '%s')" --local --dry-run`,
KubectlCmd, original, patch))
if !res.WasSuccessful() {
debugYaml(original, patch)
return res.GetErr("Cilium patch validation failed")
}
}

res = kub.Exec(fmt.Sprintf(
`%s patch --filename='%s' --patch "$(cat '%s')" --local -o yaml | kubectl apply -f -`,
KubectlCmd, original, patch))
if !res.WasSuccessful() {
debugYaml(original, patch)
return res.GetErr("Cilium manifest patch instalation failed")
}
return nil
}

// ciliumInstall installs all Cilium descriptors into kubernetes.
// dsPatchName corresponds to the DaemonSet patch, found by
// getK8sDescriptorPatch, that will be applied to the original Cilium DaemonSet
Expand All @@ -837,47 +880,6 @@ func (kub *Kubectl) ciliumInstall(dsPatchName, cmPatchName string, getK8sDescrip
if saPathname == "" {
return fmt.Errorf("Cilium ServiceAccount descriptor not found")
}
deployPatch := func(original, patch string) error {
// debugYaml only dumps the full created yaml file to the test output if
// the cilium manifest can not be created correctly.
debugYaml := func(original, patch string) {
// dry-run is only available since k8s 1.11
switch GetCurrentK8SEnv() {
case "1.8", "1.9", "1.10":
_ = kub.Exec(fmt.Sprintf(
`%s patch --filename='%s' --patch "$(cat '%s')" --local -o yaml`,
KubectlCmd, original, patch))
default:
_ = kub.Exec(fmt.Sprintf(
`%s patch --filename='%s' --patch "$(cat '%s')" --local --dry-run -o yaml`,
KubectlCmd, original, patch))
}
}

var res *CmdRes
// validation 1st
// dry-run is only available since k8s 1.11
switch GetCurrentK8SEnv() {
case "1.8", "1.9", "1.10":
default:
res = kub.Exec(fmt.Sprintf(
`%s patch --filename='%s' --patch "$(cat '%s')" --local --dry-run`,
KubectlCmd, original, patch))
if !res.WasSuccessful() {
debugYaml(original, patch)
return res.GetErr("Cilium patch validation failed")
}
}

res = kub.Exec(fmt.Sprintf(
`%s patch --filename='%s' --patch "$(cat '%s')" --local -o yaml | kubectl apply -f -`,
KubectlCmd, original, patch))
if !res.WasSuccessful() {
debugYaml(original, patch)
return res.GetErr("Cilium manifest patch instalation failed")
}
return nil
}

deployOriginal := func(original string) error {
// debugYaml only dumps the full created yaml file to the test output if
Expand Down Expand Up @@ -909,11 +911,11 @@ func (kub *Kubectl) ciliumInstall(dsPatchName, cmPatchName string, getK8sDescrip
return err
}

if err := deployPatch(cmPathname, getK8sDescriptorPatch(cmPatchName)); err != nil {
if err := kub.DeployPatch(cmPathname, getK8sDescriptorPatch(cmPatchName)); err != nil {
return err
}

if err := deployPatch(dsPathname, getK8sDescriptorPatch(dsPatchName)); err != nil {
if err := kub.DeployPatch(dsPathname, getK8sDescriptorPatch(dsPatchName)); err != nil {
return err
}
return nil
Expand All @@ -930,6 +932,19 @@ func (kub *Kubectl) CiliumInstall(dsPatchName, cmPatchName string) error {
return kub.ciliumInstall(dsPatchName, cmPatchName, GetK8sDescriptor, ManifestGet)
}

// CiliumPreFlightInstall install Cilium pre-flight DaemonSet.
func (kub *Kubectl) CiliumPreFlightInstall(patchName string) error {
dsPathname := GetK8sDescriptor(CiliumDefaultPreFlight)
if dsPathname == "" {
return fmt.Errorf("Cilium Pre-flight DaemonSet descriptor not found")
}
patchFilepath := ManifestGet(patchName)
if patchFilepath == "" {
return fmt.Errorf("Cilium pre-flight DaemonSet patch not found")
}
return kub.DeployPatch(dsPathname, patchFilepath)
}

// CiliumInstallVersion installs all Cilium descriptors into kubernetes for
// a given Cilium Version tag.
// dsPatchName corresponds to the DaemonSet patch that will be applied to the
Expand Down
9 changes: 9 additions & 0 deletions test/k8sT/Updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ func InstallAndValidateCiliumUpgrades(kubectl *helpers.Kubectl, oldVersion, newV
}
}

By("Install Cilium pre-flight check DaemonSet")
err = kubectl.CiliumPreFlightInstall(helpers.CiliumDefaultPreFlightPatch)
ExpectWithOffset(1, err).To(BeNil(), "Cilium pre-flight %q was not able to be deployed", newVersion)
ExpectCiliumPreFlightInstallReady(kubectl)

// Once they are installed we can remove it
By("Removing Cilium pre-flight check DaemonSet")
kubectl.Delete(helpers.GetK8sDescriptor(helpers.CiliumDefaultPreFlight))

err = kubectl.CiliumInstall(helpers.CiliumDefaultDSPatch, helpers.CiliumConfigMapPatch)
ExpectWithOffset(1, err).To(BeNil(), "Cilium %q was not able to be deployed", newVersion)

Expand Down
16 changes: 16 additions & 0 deletions test/k8sT/assertionHelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ func ExpectETCDOperatorReady(vm *helpers.Kubectl) {
Expect(err).To(BeNil(), "etcd-operator is not ready after timeout, pods status:\n %s", warningMessage)
}

// ExpectCiliumPreFlightInstallReady is a wrapper around helpers/WaitForNPods.
// It asserts the error returned by that function is nil.
func ExpectCiliumPreFlightInstallReady(vm *helpers.Kubectl) {
By("Waiting for all cilium pre-flight pods to be ready")

err := vm.WaitforPods(helpers.KubeSystemNamespace, "-l k8s-app=cilium-pre-flight-check", 600)
warningMessage := ""
if err != nil {
res := vm.Exec(fmt.Sprintf(
"%s -n %s get pods -l k8s-app=cilium-pre-flight-check",
helpers.KubectlCmd, helpers.KubeSystemNamespace))
warningMessage = res.Output().String()
}
Expect(err).To(BeNil(), "cilium pre-flight check is not ready after timeout, pods status:\n %s", warningMessage)
}

// ProvisionInfraPods deploys DNS, etcd-operator, and cilium into the kubernetes
// cluster of which vm is a member.
func ProvisionInfraPods(vm *helpers.Kubectl) {
Expand Down
10 changes: 10 additions & 0 deletions test/k8sT/manifests/cilium-pre-flight-patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
metadata:
namespace: kube-system
spec:
template:
spec:
containers:
- image: k8s1:5000/cilium/cilium-dev:latest
imagePullPolicy: IfNotPresent
name: cilium-pre-flight-check

0 comments on commit fc7eeef

Please sign in to comment.