@@ -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,22 @@ 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 := helpers .ExecCmdOnNode (t , cs , node , "rpm" , "-q" , "usbguard" )
162
+ if strings .Contains (foundPkg , "package usbguard is not installed" ) {
163
+ t .Fatalf ("usbguard extensions should have been installed on %s, got %s" , node .Name , foundPkg )
164
+ }
165
+ t .Logf ("usbguard extension installed, got %s" , foundPkg )
166
+ }
167
+
168
+ func assertExtensionNotOnNode (t * testing.T , cs * framework.ClientSet , node corev1.Node ) {
169
+ foundPkg := helpers .ExecCmdOnNode (t , cs , node , "rpm" , "-q" , "usbguard" )
170
+ if ! strings .Contains (foundPkg , "package usbguard is not installed" ) {
171
+ t .Fatalf ("usbguard extensions should NOT have been installed on %s, got %s" , node .Name , foundPkg )
172
+ }
173
+ t .Logf ("usbguard extension not installed as expected, got %s" , foundPkg )
174
+ }
175
+
154
176
// This test extracts the /etc/yum.repos.d and /etc/pki/rpm-gpg content from a
155
177
// Centos Stream 9 image and injects them into the MCO namespace. It then
156
178
// performs a build with the expectation that these artifacts will be used,
@@ -923,6 +945,34 @@ func prepareForOnClusterLayeringTest(t *testing.T, cs *framework.ClientSet, test
923
945
t .Cleanup (makeIdempotentAndRegister (t , helpers .CreateMCP (t , cs , testOpts .poolName )))
924
946
}
925
947
948
+ if testOpts .useExtensions {
949
+ extensionsMC := & mcfgv1.MachineConfig {
950
+ ObjectMeta : metav1.ObjectMeta {
951
+ Name : "99-extensions" ,
952
+ Labels : helpers .MCLabelForRole (testOpts .poolName ),
953
+ },
954
+ Spec : mcfgv1.MachineConfigSpec {
955
+ Config : runtime.RawExtension {
956
+ Raw : helpers .MarshalOrDie (ctrlcommon .NewIgnConfig ()),
957
+ },
958
+ Extensions : []string {"usbguard" },
959
+ },
960
+ }
961
+
962
+ helpers .SetMetadataOnObject (t , extensionsMC )
963
+ // Apply the extensions MC
964
+ mcCleanupFunc := helpers .ApplyMC (t , cs , extensionsMC )
965
+ t .Cleanup (func () {
966
+ mcCleanupFunc ()
967
+ t .Logf ("Deleted MachineConfig %s" , extensionsMC .Name )
968
+ })
969
+ t .Logf ("Created new MachineConfig %q" , extensionsMC .Name )
970
+ // Wait for rendered config to finish creating
971
+ renderedConfig , err := helpers .WaitForRenderedConfig (t , cs , testOpts .poolName , extensionsMC .Name )
972
+ require .NoError (t , err )
973
+ t .Logf ("Finished rendering config %s" , renderedConfig )
974
+ }
975
+
926
976
_ , err := helpers .WaitForRenderedConfig (t , cs , testOpts .poolName , "00-worker" )
927
977
require .NoError (t , err )
928
978
0 commit comments