@@ -88,6 +88,9 @@ type onClusterLayeringTestOpts struct {
88
88
89
89
// Inject YUM repo information from a Centos 9 stream container
90
90
useYumRepos bool
91
+
92
+ // Add Extensions for testing
93
+ useExtensions bool
91
94
}
92
95
93
96
func TestOnClusterBuildsOnOKD (t * testing.T ) {
@@ -113,12 +116,14 @@ func TestOnClusterBuildsCustomPodBuilder(t *testing.T) {
113
116
114
117
// Tests that an on-cluster build can be performed and that the resulting image
115
118
// is rolled out to an opted-in node.
116
- func TestOnClusterBuildRollsOutImage (t * testing.T ) {
119
+ func TestOnClusterBuildRollsOutImageWithExtensionsInstalled (t * testing.T ) {
117
120
imagePullspec := runOnClusterLayeringTest (t , onClusterLayeringTestOpts {
118
121
poolName : layeredMCPName ,
119
122
customDockerfiles : map [string ]string {
120
123
layeredMCPName : cowsayDockerfile ,
121
124
},
125
+ useEtcPkiEntitlement : true ,
126
+ useExtensions : true ,
122
127
})
123
128
124
129
cs := framework .NewClientSet ("" )
@@ -129,12 +134,14 @@ func TestOnClusterBuildRollsOutImage(t *testing.T) {
129
134
130
135
helpers .AssertNodeBootedIntoImage (t , cs , node , imagePullspec )
131
136
t .Logf ("Node %s is booted into image %q" , node .Name , imagePullspec )
137
+ assertExtensionInstalledOnNode (t , cs , node )
132
138
133
139
t .Log (helpers .ExecCmdOnNode (t , cs , node , "chroot" , "/rootfs" , "cowsay" , "Moo!" ))
134
140
135
141
unlabelFunc ()
136
142
137
143
assertNodeRevertsToNonLayered (t , cs , node )
144
+ assertExtensionNotOnNode (t , cs , node )
138
145
}
139
146
140
147
func assertNodeRevertsToNonLayered (t * testing.T , cs * framework.ClientSet , node corev1.Node ) {
@@ -151,6 +158,30 @@ func assertNodeRevertsToNonLayered(t *testing.T, cs *framework.ClientSet, node c
151
158
helpers .AssertFileNotOnNode (t , cs , node , runtimeassets .RevertServiceMachineConfigFile )
152
159
}
153
160
161
+ func assertExtensionInstalledOnNode (t * testing.T , cs * framework.ClientSet , node corev1.Node ) {
162
+ foundPkg , err := helpers .ExecCmdOnNodeWithError (cs , node , "rpm" , "-q" , "usbguard" )
163
+ require .NoError (t , err , "usbguard extension not found" )
164
+ t .Logf ("usbguard extension installed, got %s" , foundPkg )
165
+
166
+ foundPkg , err = helpers .ExecCmdOnNodeWithError (cs , node , "rpm" , "-q" , "kerberos" )
167
+ require .NoError (t , err , "kerberos extension not found" )
168
+ t .Logf ("kerberos extension installed, got %s" , foundPkg )
169
+
170
+ t .Logf ("Node %s has both usbguard and kerberos extensions installed" , node .Name )
171
+ }
172
+
173
+ func assertExtensionNotOnNode (t * testing.T , cs * framework.ClientSet , node corev1.Node ) {
174
+ foundPkg , err := helpers .ExecCmdOnNodeWithError (cs , node , "rpm" , "-q" , "usbguard" )
175
+ require .Error (t , err , "usbguard extension is on node" )
176
+ t .Logf ("usbguard extension not installed as expected, got %s" , foundPkg )
177
+
178
+ foundPkg , err = helpers .ExecCmdOnNodeWithError (cs , node , "rpm" , "-q" , "kerberos" )
179
+ require .Error (t , err , "kerberos extension is on node" )
180
+ t .Logf ("kerberos extension not installed as expected, got %s" , foundPkg )
181
+
182
+ t .Logf ("Node %s does not have usbguard and kerberos extensions installed as expected" , node .Name )
183
+ }
184
+
154
185
// This test extracts the /etc/yum.repos.d and /etc/pki/rpm-gpg content from a
155
186
// Centos Stream 9 image and injects them into the MCO namespace. It then
156
187
// performs a build with the expectation that these artifacts will be used,
@@ -923,6 +954,34 @@ func prepareForOnClusterLayeringTest(t *testing.T, cs *framework.ClientSet, test
923
954
t .Cleanup (makeIdempotentAndRegister (t , helpers .CreateMCP (t , cs , testOpts .poolName )))
924
955
}
925
956
957
+ if testOpts .useExtensions {
958
+ extensionsMC := & mcfgv1.MachineConfig {
959
+ ObjectMeta : metav1.ObjectMeta {
960
+ Name : "99-extensions" ,
961
+ Labels : helpers .MCLabelForRole (testOpts .poolName ),
962
+ },
963
+ Spec : mcfgv1.MachineConfigSpec {
964
+ Config : runtime.RawExtension {
965
+ Raw : helpers .MarshalOrDie (ctrlcommon .NewIgnConfig ()),
966
+ },
967
+ Extensions : []string {"usbguard" , "kerberos" },
968
+ },
969
+ }
970
+
971
+ helpers .SetMetadataOnObject (t , extensionsMC )
972
+ // Apply the extensions MC
973
+ mcCleanupFunc := helpers .ApplyMC (t , cs , extensionsMC )
974
+ t .Cleanup (func () {
975
+ mcCleanupFunc ()
976
+ t .Logf ("Deleted MachineConfig %s" , extensionsMC .Name )
977
+ })
978
+ t .Logf ("Created new MachineConfig %q" , extensionsMC .Name )
979
+ // Wait for rendered config to finish creating
980
+ renderedConfig , err := helpers .WaitForRenderedConfig (t , cs , testOpts .poolName , extensionsMC .Name )
981
+ require .NoError (t , err )
982
+ t .Logf ("Finished rendering config %s" , renderedConfig )
983
+ }
984
+
926
985
_ , err := helpers .WaitForRenderedConfig (t , cs , testOpts .poolName , "00-worker" )
927
986
require .NoError (t , err )
928
987
0 commit comments