@@ -1098,6 +1098,16 @@ func (o *Operator) createInstallPlan(namespace string, gen int, subs []*v1alpha1
1098
1098
return reference .GetReference (res )
1099
1099
}
1100
1100
1101
+ type UnpackedBundleReference struct {
1102
+ Kind string `json:"kind"`
1103
+ Name string `json:"name"`
1104
+ Namespace string `json:"namespace"`
1105
+ CatalogSourceName string `json:"catalogSourceName"`
1106
+ CatalogSourceNamespace string `json:"catalogSourceNamespace"`
1107
+ Replaces string `json:"replaces"`
1108
+ }
1109
+
1110
+ // unpackBundles makes one walk through the bundlelookups and attempts to progress them
1101
1111
func (o * Operator ) unpackBundles (plan * v1alpha1.InstallPlan ) (bool , * v1alpha1.InstallPlan , error ) {
1102
1112
out := plan .DeepCopy ()
1103
1113
unpacked := true
@@ -1110,32 +1120,53 @@ func (o *Operator) unpackBundles(plan *v1alpha1.InstallPlan) (bool, *v1alpha1.In
1110
1120
errs = append (errs , err )
1111
1121
continue
1112
1122
}
1123
+ out .Status .BundleLookups [i ] = * res .BundleLookup
1113
1124
1114
- if res == nil {
1125
+ // if pending condition is present, still waiting for the job to unpack to configmap
1126
+ if res .GetCondition (v1alpha1 .BundleLookupPending ).Status == corev1 .ConditionTrue {
1115
1127
unpacked = false
1116
1128
continue
1117
1129
}
1118
1130
1119
- out .Status .BundleLookups [i ] = * res .BundleLookup
1120
- if res .Bundle () == nil || len (res .Bundle ().GetObject ()) == 0 {
1121
- unpacked = false
1131
+ // if packed condition is missing, bundle has already been unpacked into steps, continue
1132
+ if res .GetCondition (resolver .BundleLookupConditionPacked ).Status == corev1 .ConditionUnknown {
1122
1133
continue
1123
1134
}
1124
1135
1136
+ // Ensure that bundle can be applied by the current version of OLM by converting to steps
1125
1137
steps , err := resolver .NewStepsFromBundle (res .Bundle (), out .GetNamespace (), res .Replaces , res .CatalogSourceRef .Name , res .CatalogSourceRef .Namespace )
1126
1138
if err != nil {
1127
- errs = append (errs , fmt .Errorf ("failed to turn bundle into steps: %s " , err . Error () ))
1139
+ errs = append (errs , fmt .Errorf ("failed to turn bundle into steps: %v " , err ))
1128
1140
unpacked = false
1129
1141
continue
1130
1142
}
1131
1143
1132
- // Add steps and remove resolved bundle lookup
1144
+ // step manifests are replaced with references to the configmap containing them
1145
+ for i , s := range steps {
1146
+ ref := UnpackedBundleReference {
1147
+ Kind : "ConfigMap" ,
1148
+ Namespace : res .CatalogSourceRef .Namespace ,
1149
+ Name : res .Name (),
1150
+ CatalogSourceName : res .CatalogSourceRef .Name ,
1151
+ CatalogSourceNamespace : res .CatalogSourceRef .Namespace ,
1152
+ Replaces : res .Replaces ,
1153
+ }
1154
+ r , err := json .Marshal (& ref )
1155
+ if err != nil {
1156
+ errs = append (errs , fmt .Errorf ("failed to generate reference for configmap: %v" , err ))
1157
+ unpacked = false
1158
+ continue
1159
+ }
1160
+ s .Resource .Manifest = string (r )
1161
+ steps [i ] = s
1162
+ }
1163
+ res .RemoveCondition (resolver .BundleLookupConditionPacked )
1164
+ out .Status .BundleLookups [i ] = * res .BundleLookup
1133
1165
out .Status .Plan = append (out .Status .Plan , steps ... )
1134
- out .Status .BundleLookups = append (out .Status .BundleLookups [:i ], out .Status .BundleLookups [i + 1 :]... )
1135
- i --
1136
1166
}
1137
1167
1138
1168
if err := utilerrors .NewAggregate (errs ); err != nil {
1169
+ o .logger .Debugf ("failed to unpack bundles: %v" , err )
1139
1170
return false , nil , err
1140
1171
}
1141
1172
@@ -1436,6 +1467,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
1436
1467
}
1437
1468
1438
1469
ensurer := newStepEnsurer (kubeclient , crclient , dynamicClient )
1470
+ r := newManifestResolver (plan .GetNamespace (), o .lister .CoreV1 ().ConfigMapLister (), o .logger )
1439
1471
1440
1472
for i , step := range plan .Status .Plan {
1441
1473
switch step .Status {
@@ -1474,6 +1506,10 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
1474
1506
continue
1475
1507
}
1476
1508
case v1alpha1 .StepStatusUnknown , v1alpha1 .StepStatusNotPresent :
1509
+ manifest , err := r .ManifestForStep (step )
1510
+ if err != nil {
1511
+ return err
1512
+ }
1477
1513
o .logger .WithFields (logrus.Fields {"kind" : step .Resource .Kind , "name" : step .Resource .Name }).Debug ("execute resource" )
1478
1514
switch step .Resource .Kind {
1479
1515
case crdKind :
@@ -1546,7 +1582,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
1546
1582
case v1alpha1 .ClusterServiceVersionKind :
1547
1583
// Marshal the manifest into a CSV instance.
1548
1584
var csv v1alpha1.ClusterServiceVersion
1549
- err := json .Unmarshal ([]byte (step . Resource . Manifest ), & csv )
1585
+ err := json .Unmarshal ([]byte (manifest ), & csv )
1550
1586
if err != nil {
1551
1587
return errorwrap .Wrapf (err , "error parsing step manifest: %s" , step .Resource .Name )
1552
1588
}
@@ -1579,7 +1615,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
1579
1615
case v1alpha1 .SubscriptionKind :
1580
1616
// Marshal the manifest into a subscription instance.
1581
1617
var sub v1alpha1.Subscription
1582
- err := json .Unmarshal ([]byte (step . Resource . Manifest ), & sub )
1618
+ err := json .Unmarshal ([]byte (manifest ), & sub )
1583
1619
if err != nil {
1584
1620
return errorwrap .Wrapf (err , "error parsing step manifest: %s" , step .Resource .Name )
1585
1621
}
@@ -1612,7 +1648,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
1612
1648
case clusterRoleKind :
1613
1649
// Marshal the manifest into a ClusterRole instance.
1614
1650
var cr rbacv1.ClusterRole
1615
- err := json .Unmarshal ([]byte (step . Resource . Manifest ), & cr )
1651
+ err := json .Unmarshal ([]byte (manifest ), & cr )
1616
1652
if err != nil {
1617
1653
return errorwrap .Wrapf (err , "error parsing step manifest: %s" , step .Resource .Name )
1618
1654
}
@@ -1627,7 +1663,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
1627
1663
case clusterRoleBindingKind :
1628
1664
// Marshal the manifest into a RoleBinding instance.
1629
1665
var rb rbacv1.ClusterRoleBinding
1630
- err := json .Unmarshal ([]byte (step . Resource . Manifest ), & rb )
1666
+ err := json .Unmarshal ([]byte (manifest ), & rb )
1631
1667
if err != nil {
1632
1668
return errorwrap .Wrapf (err , "error parsing step manifest: %s" , step .Resource .Name )
1633
1669
}
@@ -1642,7 +1678,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
1642
1678
case roleKind :
1643
1679
// Marshal the manifest into a Role instance.
1644
1680
var r rbacv1.Role
1645
- err := json .Unmarshal ([]byte (step . Resource . Manifest ), & r )
1681
+ err := json .Unmarshal ([]byte (manifest ), & r )
1646
1682
if err != nil {
1647
1683
return errorwrap .Wrapf (err , "error parsing step manifest: %s" , step .Resource .Name )
1648
1684
}
@@ -1665,7 +1701,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
1665
1701
case roleBindingKind :
1666
1702
// Marshal the manifest into a RoleBinding instance.
1667
1703
var rb rbacv1.RoleBinding
1668
- err := json .Unmarshal ([]byte (step . Resource . Manifest ), & rb )
1704
+ err := json .Unmarshal ([]byte (manifest ), & rb )
1669
1705
if err != nil {
1670
1706
return errorwrap .Wrapf (err , "error parsing step manifest: %s" , step .Resource .Name )
1671
1707
}
@@ -1688,7 +1724,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
1688
1724
case serviceAccountKind :
1689
1725
// Marshal the manifest into a ServiceAccount instance.
1690
1726
var sa corev1.ServiceAccount
1691
- err := json .Unmarshal ([]byte (step . Resource . Manifest ), & sa )
1727
+ err := json .Unmarshal ([]byte (manifest ), & sa )
1692
1728
if err != nil {
1693
1729
return errorwrap .Wrapf (err , "error parsing step manifest: %s" , step .Resource .Name )
1694
1730
}
@@ -1711,7 +1747,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
1711
1747
case serviceKind :
1712
1748
// Marshal the manifest into a Service instance
1713
1749
var s corev1.Service
1714
- err := json .Unmarshal ([]byte (step . Resource . Manifest ), & s )
1750
+ err := json .Unmarshal ([]byte (manifest ), & s )
1715
1751
if err != nil {
1716
1752
return errorwrap .Wrapf (err , "error parsing step manifest: %s" , step .Resource .Name )
1717
1753
}
@@ -1739,7 +1775,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
1739
1775
}
1740
1776
1741
1777
// Marshal the manifest into an unstructured object
1742
- dec := yaml .NewYAMLOrJSONDecoder (strings .NewReader (step . Resource . Manifest ), 10 )
1778
+ dec := yaml .NewYAMLOrJSONDecoder (strings .NewReader (manifest ), 10 )
1743
1779
unstructuredObject := & unstructured.Unstructured {}
1744
1780
if err := dec .Decode (unstructuredObject ); err != nil {
1745
1781
return errorwrap .Wrapf (err , "error decoding %s object to an unstructured object" , step .Resource .Name )
0 commit comments