|
| 1 | +package controllers |
| 2 | + |
| 3 | +import ( |
| 4 | + k8serrors "k8s.io/apimachinery/pkg/api/errors" |
| 5 | +) |
| 6 | + |
| 7 | +// When the feature is enabled, handleFeatureConfidential sets config maps to confidential values. |
| 8 | +// |
| 9 | +// Changes the ImageConfigMap, so that the image creation job will create a confidential image. |
| 10 | +// This will happen at the first reconciliation loop, before the image creation job starts. |
| 11 | +// |
| 12 | +// Changes the peer pods configMap to enable confidential. |
| 13 | +// This will happen likely after several reconciliation loops, because it has prerequisites: |
| 14 | +// |
| 15 | +// - Peer pods must be enabled in the KataConfig. |
| 16 | +// - The peer pods config map must exist. |
| 17 | +// |
| 18 | +// When the feature is disabled, handleFeatureConfidential resets the config maps to non-confidential values. |
| 19 | +func (r *KataConfigOpenShiftReconciler) handleFeatureConfidential(state FeatureGateState) error { |
| 20 | + |
| 21 | + // ImageConfigMap |
| 22 | + |
| 23 | + if err := InitializeImageGenerator(r.Client); err != nil { |
| 24 | + return err |
| 25 | + } |
| 26 | + ig := GetImageGenerator() |
| 27 | + |
| 28 | + if ig.provider == unsupportedCloudProvider { |
| 29 | + r.Log.Info("unsupported cloud provider, skipping confidential image configuration") |
| 30 | + } else { |
| 31 | + if ig.isImageIDSet() { |
| 32 | + r.Log.Info("Image ID is already set, skipping confidential image configuration") |
| 33 | + } else { |
| 34 | + if state == Enabled { |
| 35 | + // Create ImageConfigMap, if it doesn't exist already. |
| 36 | + if err := ig.createImageConfigMapFromFile(); err != nil { |
| 37 | + return err |
| 38 | + } |
| 39 | + |
| 40 | + // Patch ImageConfigMap. |
| 41 | + imageConfigMapData := map[string]string{"CONFIDENTIAL_COMPUTE_ENABLED": "yes"} |
| 42 | + if err := updateConfigMap(r.Client, r.Log, ig.getImageConfigMapName(), OperatorNamespace, imageConfigMapData); err != nil { |
| 43 | + return err |
| 44 | + } |
| 45 | + } else { |
| 46 | + // Patch ImageConfigMap. |
| 47 | + imageConfigMapData := map[string]string{"CONFIDENTIAL_COMPUTE_ENABLED": "no"} |
| 48 | + if err := updateConfigMap(r.Client, r.Log, ig.getImageConfigMapName(), OperatorNamespace, imageConfigMapData); err != nil { |
| 49 | + if k8serrors.IsNotFound(err) { |
| 50 | + // Nothing to do, feature is disabled and configMap doesn't exist. |
| 51 | + } else { |
| 52 | + return err |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + // peer pods config |
| 60 | + |
| 61 | + // Patch peer pods configMap, if it exists. |
| 62 | + var peerpodsCMData map[string]string |
| 63 | + if state == Enabled { |
| 64 | + peerpodsCMData = map[string]string{"DISABLECVM": "false"} |
| 65 | + } else { |
| 66 | + peerpodsCMData = map[string]string{"DISABLECVM": "true"} |
| 67 | + } |
| 68 | + if err := updateConfigMap(r.Client, r.Log, peerpodsCMName, OperatorNamespace, peerpodsCMData); err != nil { |
| 69 | + if k8serrors.IsNotFound(err) { |
| 70 | + // When feature is Enabled: ConfigMap doesn't exist yet, will try again at the next reconcile run. |
| 71 | + // Else: Nothing to do, feature is disabled and configMap doesn't exist. |
| 72 | + } else { |
| 73 | + return err |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + return nil |
| 78 | +} |
0 commit comments