@@ -2,6 +2,7 @@ package controllers
2
2
3
3
import (
4
4
"context"
5
+ "strconv"
5
6
6
7
corev1 "k8s.io/api/core/v1"
7
8
k8serrors "k8s.io/apimachinery/pkg/api/errors"
@@ -12,15 +13,19 @@ const (
12
13
FgConfigMapName = "osc-feature-gates"
13
14
ConfidentialFeatureGate = "confidential"
14
15
LayeredImageDeployment = "layeredImageDeployment"
16
+ DeploymentModeConfig = "deploymentMode"
15
17
)
16
18
17
- var DefaultFeatureGates = map [string ]bool {
18
- ConfidentialFeatureGate : false ,
19
- LayeredImageDeployment : false ,
19
+ var DefaultFeatureGates = FeatureGateStatus {
20
+ Confidential : false ,
21
+ LayeredImageDeployment : false ,
22
+ DeploymentModeOption : MachineConfigOption ,
20
23
}
21
24
22
25
type FeatureGateStatus struct {
23
- FeatureGates map [string ]bool
26
+ Confidential bool
27
+ LayeredImageDeployment bool
28
+ DeploymentModeOption DeploymentModeOption
24
29
}
25
30
26
31
// Create enum to represent the state of the feature gates
@@ -40,22 +45,38 @@ const (
40
45
// Return an error for any other reason, such as an API error.
41
46
func (r * KataConfigOpenShiftReconciler ) NewFeatureGateStatus () (* FeatureGateStatus , error ) {
42
47
fgStatus := & FeatureGateStatus {
43
- FeatureGates : make (map [string ]bool ),
48
+ Confidential : DefaultFeatureGates .Confidential ,
49
+ LayeredImageDeployment : DefaultFeatureGates .LayeredImageDeployment ,
50
+ DeploymentModeOption : DefaultFeatureGates .DeploymentModeOption ,
44
51
}
45
52
46
53
cfgMap := & corev1.ConfigMap {}
47
54
err := r .Client .Get (context .TODO (), types.NamespacedName {Name : FgConfigMapName ,
48
55
Namespace : OperatorNamespace }, cfgMap )
49
56
if err == nil {
50
- for feature , value := range cfgMap .Data {
51
- fgStatus .FeatureGates [feature ] = value == "true"
57
+ if value , ok := cfgMap .Data [ConfidentialFeatureGate ]; ok {
58
+ confidential , err := strconv .ParseBool (value )
59
+ if err != nil {
60
+ r .Log .Info ("Couldn't parse confidential status, using default value" , "default" , DefaultFeatureGates .Confidential , "error" , err )
61
+ } else {
62
+ fgStatus .Confidential = confidential
63
+ }
52
64
}
53
- }
54
-
55
- // Add default values for missing feature gates
56
- for feature , defaultValue := range DefaultFeatureGates {
57
- if _ , exists := fgStatus .FeatureGates [feature ]; ! exists {
58
- fgStatus .FeatureGates [feature ] = defaultValue
65
+ if value , ok := cfgMap .Data [LayeredImageDeployment ]; ok {
66
+ layeredImageDeployment , err := strconv .ParseBool (value )
67
+ if err != nil {
68
+ r .Log .Info ("Couldn't parse layeredImageDeployment status, using default value" , "default" , DefaultFeatureGates .LayeredImageDeployment , "error" , err )
69
+ } else {
70
+ fgStatus .LayeredImageDeployment = layeredImageDeployment
71
+ }
72
+ }
73
+ if value , ok := cfgMap .Data [DeploymentModeConfig ]; ok {
74
+ mode , err := ParseDeploymentModeOption (value )
75
+ if err != nil {
76
+ r .Log .Info ("Couldn't parse deploymentMode status, using default value" , "default" , DefaultFeatureGates .DeploymentModeOption , "error" , err )
77
+ } else {
78
+ fgStatus .DeploymentModeOption = mode
79
+ }
59
80
}
60
81
}
61
82
@@ -66,8 +87,16 @@ func (r *KataConfigOpenShiftReconciler) NewFeatureGateStatus() (*FeatureGateStat
66
87
}
67
88
}
68
89
69
- func IsEnabled (fgStatus * FeatureGateStatus , feature string ) bool {
70
- return fgStatus .FeatureGates [feature ]
90
+ var statusChecker = map [string ]func (fgstatus * FeatureGateStatus ) bool {
91
+ ConfidentialFeatureGate : func (fgstatus * FeatureGateStatus ) bool { return fgstatus .Confidential },
92
+ LayeredImageDeployment : func (fgstatus * FeatureGateStatus ) bool { return fgstatus .LayeredImageDeployment },
93
+ }
94
+
95
+ func (fgstatus * FeatureGateStatus ) IsEnabled (key string ) bool {
96
+ if checkStatus , ok := statusChecker [key ]; ok {
97
+ return checkStatus (fgstatus )
98
+ }
99
+ return false
71
100
}
72
101
73
102
// Function to handle the feature gates
@@ -82,7 +111,7 @@ func (r *KataConfigOpenShiftReconciler) processFeatureGates() error {
82
111
// Check which feature gates are enabled in the FG ConfigMap and
83
112
// perform the necessary actions
84
113
if r .kataConfig .Spec .EnablePeerPods {
85
- if IsEnabled (fgStatus , ConfidentialFeatureGate ) {
114
+ if fgStatus . IsEnabled (ConfidentialFeatureGate ) {
86
115
r .Log .Info ("Feature gate is enabled" , "featuregate" , ConfidentialFeatureGate )
87
116
// Perform the necessary actions
88
117
if err := r .handleFeatureConfidential (Enabled ); err != nil {
@@ -97,8 +126,17 @@ func (r *KataConfigOpenShiftReconciler) processFeatureGates() error {
97
126
}
98
127
}
99
128
129
+ if err := r .handleDeploymentModeFeature (fgStatus .DeploymentModeOption ); err != nil {
130
+ return err
131
+ }
132
+
133
+ if r .DeploymentMode == DaemonSetMode {
134
+ r .Log .Info ("Skipping layered image deployment feature, not using MCO" )
135
+ return nil
136
+ }
137
+
100
138
// Check layered Image deployment FG
101
- if IsEnabled (fgStatus , LayeredImageDeployment ) {
139
+ if fgStatus . IsEnabled (LayeredImageDeployment ) {
102
140
r .Log .Info ("Feature gate is enabled" , "featuregate" , LayeredImageDeployment )
103
141
// Perform the necessary actions
104
142
return r .handleLayeredImageDeploymentFeature (Enabled )
0 commit comments