Skip to content

Commit 427efa6

Browse files
Merge pull request #1913 from awgreene/fix-deployment-annotation-bug
Bug 1907381: CSV Annotations override pod annotations
2 parents 72d0608 + 7eb83c0 commit 427efa6

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

16211697
// Create dependency first (CRD)

0 commit comments

Comments
 (0)