Skip to content

Commit 7eb83c0

Browse files
committed
CSV Annotations override pod annotations
Problem: If a pod template defined in a CSV's StrategyDetailsDeployment includes an annotation defined for the CSV OLM will fail to install the operator because the pod's annotations do not match those defined in the CSV. Solution: Pod template annotations defined in a StrategyDetailsDeployment are overwritten by those defined in the CSV.
1 parent ffb66b0 commit 7eb83c0

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

pkg/controller/install/deployment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ func (i *StrategyDeploymentInstaller) deploymentForSpec(name string, spec appsv1
134134

135135
// Merge annotations (to avoid losing info from pod template)
136136
annotations := map[string]string{}
137-
for k, v := range i.templateAnnotations {
137+
for k, v := range dep.Spec.Template.GetAnnotations() {
138138
annotations[k] = v
139139
}
140-
for k, v := range dep.Spec.Template.GetAnnotations() {
140+
for k, v := range i.templateAnnotations {
141141
annotations[k] = v
142142
}
143143
dep.Spec.Template.SetAnnotations(annotations)

test/e2e/csv_e2e_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,82 @@ var _ = Describe("ClusterServiceVersion", func() {
16091609
Expect(err).ShouldNot(HaveOccurred(), "error updating APIService")
16101610
<-deleted
16111611
})
1612+
It("CSV annotations overwrite pod template annotations defined in a StrategyDetailsDeployment", func() {
1613+
// Create a StrategyDetailsDeployment that defines the `foo1` and `foo2` annotations on a pod template
1614+
nginxName := genName("nginx-")
1615+
strategy := v1alpha1.StrategyDetailsDeployment{
1616+
DeploymentSpecs: []v1alpha1.StrategyDeploymentSpec{
1617+
{
1618+
Name: genName("dep-"),
1619+
Spec: newNginxDeployment(nginxName),
1620+
},
1621+
},
1622+
}
1623+
strategy.DeploymentSpecs[0].Spec.Template.Annotations = map[string]string{
1624+
"foo1": "notBar1",
1625+
"foo2": "bar2",
1626+
}
1627+
1628+
// Create a CSV that defines the `foo1` and `foo3` annotations
1629+
csv := v1alpha1.ClusterServiceVersion{
1630+
TypeMeta: metav1.TypeMeta{
1631+
Kind: v1alpha1.ClusterServiceVersionKind,
1632+
APIVersion: v1alpha1.ClusterServiceVersionAPIVersion,
1633+
},
1634+
ObjectMeta: metav1.ObjectMeta{
1635+
Name: genName("csv"),
1636+
Annotations: map[string]string{
1637+
"foo1": "bar1",
1638+
"foo3": "bar3",
1639+
},
1640+
},
1641+
Spec: v1alpha1.ClusterServiceVersionSpec{
1642+
MinKubeVersion: "0.0.0",
1643+
InstallModes: []v1alpha1.InstallMode{
1644+
{
1645+
Type: v1alpha1.InstallModeTypeOwnNamespace,
1646+
Supported: true,
1647+
},
1648+
{
1649+
Type: v1alpha1.InstallModeTypeSingleNamespace,
1650+
Supported: true,
1651+
},
1652+
{
1653+
Type: v1alpha1.InstallModeTypeMultiNamespace,
1654+
Supported: true,
1655+
},
1656+
{
1657+
Type: v1alpha1.InstallModeTypeAllNamespaces,
1658+
Supported: true,
1659+
},
1660+
},
1661+
InstallStrategy: v1alpha1.NamedInstallStrategy{
1662+
StrategyName: v1alpha1.InstallStrategyNameDeployment,
1663+
StrategySpec: strategy,
1664+
},
1665+
},
1666+
}
1667+
1668+
// Create the CSV and make sure to clean it up
1669+
cleanupCSV, err := createCSV(c, crc, csv, testNamespace, false, false)
1670+
Expect(err).ShouldNot(HaveOccurred())
1671+
defer cleanupCSV()
1672+
1673+
// Wait for current CSV to succeed
1674+
_, err = fetchCSV(crc, csv.Name, testNamespace, csvSucceededChecker)
1675+
Expect(err).ShouldNot(HaveOccurred())
1676+
1677+
// Should have created deployment
1678+
dep, err := c.GetDeployment(testNamespace, strategy.DeploymentSpecs[0].Name)
1679+
Expect(err).ShouldNot(HaveOccurred())
1680+
Expect(dep).ShouldNot(BeNil())
1681+
1682+
// Make sure that the pods annotations are correct
1683+
annotations := dep.Spec.Template.Annotations
1684+
Expect(annotations["foo1"]).Should(Equal("bar1"))
1685+
Expect(annotations["foo2"]).Should(Equal("bar2"))
1686+
Expect(annotations["foo3"]).Should(Equal("bar3"))
1687+
})
16121688
It("update same deployment name", func() {
16131689

16141690
// Create dependency first (CRD)

0 commit comments

Comments
 (0)