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