Skip to content

Commit 0d16699

Browse files
committed
implement requested changes
1 parent c53a075 commit 0d16699

7 files changed

Lines changed: 35 additions & 18 deletions

File tree

pkg/apis/testextension/v1/types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,13 @@ type TestExtensionAdmissionStatus struct {
3232
// +optional
3333
Conditions []metav1.Condition `json:"conditions,omitempty"`
3434
}
35+
36+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
37+
38+
// TestExtensionAdmissionList contains a list of TestExtensionAdmission
39+
type TestExtensionAdmissionList struct {
40+
metav1.TypeMeta `json:",inline"`
41+
metav1.ListMeta `json:"metadata,omitempty"`
42+
43+
Items []TestExtensionAdmission `json:"items"`
44+
}

pkg/cmd/openshift-tests/extension-admission/extension_admission_command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ func (o *extensionAdmissionOptions) applyYAML(yamlBytes []byte) error {
163163
return fmt.Errorf("failed to create temp file: %w", err)
164164
}
165165
defer os.Remove(tmpFile.Name())
166-
defer tmpFile.Close()
167166

168167
if _, err := tmpFile.Write(yamlBytes); err != nil {
168+
tmpFile.Close()
169169
return fmt.Errorf("failed to write YAML to temp file: %w", err)
170170
}
171171
tmpFile.Close()

pkg/cmd/openshift-tests/extension-admission/testextensionadmission-crd.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ spec:
2828
properties:
2929
permit:
3030
type: array
31-
description: List of permitted ImageStream patterns in format "namespace/imagestream". Supports wildcards like "openshift/*", "*/*", or specific "namespace/stream"
31+
description: List of permitted ImageStream patterns in format "namespace/imagestream". Each segment must be either "*" (wildcard) or a valid name (no embedded wildcards). Examples - "openshift/*", "*/*", "namespace/stream"
32+
minItems: 1
3233
items:
3334
type: string
34-
pattern: '^[a-zA-Z0-9\*]([a-zA-Z0-9\-\_\*]*[a-zA-Z0-9\*])?/[a-zA-Z0-9\*]([a-zA-Z0-9\-\_\*]*[a-zA-Z0-9\*])?$'
35+
pattern: '^(\*|[a-zA-Z0-9]([-_a-zA-Z0-9]*[a-zA-Z0-9])?)/(\*|[a-zA-Z0-9]([-_a-zA-Z0-9]*[a-zA-Z0-9])?)$'
3536
required:
3637
- permit
3738
status:

pkg/test/extensions/binary.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,8 +1033,8 @@ func (s nonPayloadSource) imageTag() string {
10331033

10341034
// discoverNonPayloadExtensions lists ImageStreamTags with ComponentAnnotation in all namespaces,
10351035
// parses binary annotation and image ref, and splits into permitted vs unpermitted by the admission result.
1036-
func discoverNonPayloadExtensions(ctx context.Context, oc *exutil.CLI, permitPatters []PermitPattern) (permitted []nonPayloadSource, unpermitted []UnpermittedExtension, err error) {
1037-
if len(permitPatters) == 0 {
1036+
func discoverNonPayloadExtensions(ctx context.Context, oc *exutil.CLI, permitPatterns []PermitPattern) (permitted []nonPayloadSource, unpermitted []UnpermittedExtension, err error) {
1037+
if len(permitPatterns) == 0 {
10381038
return nil, nil, nil
10391039
}
10401040
imageClient := oc.AdminImageClient().ImageV1()
@@ -1076,7 +1076,7 @@ func discoverNonPayloadExtensions(ctx context.Context, oc *exutil.CLI, permitPat
10761076
Component: component,
10771077
BinaryArgs: binArgs,
10781078
}
1079-
if MatchesAnyPermit(namespace, streamName, permitPatters) {
1079+
if MatchesAnyPermit(namespace, streamName, permitPatterns) {
10801080
permitted = append(permitted, source)
10811081
} else {
10821082
unpermitted = append(unpermitted, UnpermittedExtension{

pkg/test/extensions/non-payload-binary-admission.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66

77
"github.com/sirupsen/logrus"
8+
apierrors "k8s.io/apimachinery/pkg/api/errors"
89
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
910
"k8s.io/apimachinery/pkg/runtime"
1011
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -117,10 +118,5 @@ func DiscoverNonPayloadBinaryAdmission(ctx context.Context, config *rest.Config)
117118
}
118119

119120
func isNotFound(err error) bool {
120-
if err == nil {
121-
return false
122-
}
123-
return strings.Contains(err.Error(), "not found") ||
124-
strings.Contains(err.Error(), "NotFound") ||
125-
strings.Contains(err.Error(), "the server could not find the requested resource")
121+
return apierrors.IsNotFound(err)
126122
}

pkg/test/extensions/provider.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,17 @@ func (provider *ExternalBinaryProvider) extractBinary(imageRef, binaryPath, targ
108108

109109
// Check if the binary already exists in cache
110110
if _, err := os.Stat(finalBinPath); err == nil {
111-
logrus.Infof("Using existing binary %s for %s", finalBinPath, imageTag)
112-
return finalBinPath, 0, nil
111+
// Revalidate architecture compatibility before returning cached binary
112+
if err := checkCompatibleArchitecture(finalBinPath); err != nil {
113+
logrus.Warnf("Cached binary %s for %s is incompatible with current architecture, removing: %v", finalBinPath, imageTag, err)
114+
if removeErr := os.Remove(finalBinPath); removeErr != nil {
115+
logrus.Warnf("Failed to remove incompatible cached binary %s: %v", finalBinPath, removeErr)
116+
}
117+
// Continue with normal extraction flow
118+
} else {
119+
logrus.Infof("Using existing binary %s for %s", finalBinPath, imageTag)
120+
return finalBinPath, 0, nil
121+
}
113122
}
114123

115124
// Start the extraction process
@@ -281,7 +290,7 @@ func cleanOldCacheFiles(dir string) {
281290
}
282291

283292
func binaryPathOverride(imageTag, binaryPath string) string {
284-
safeEnvVar := strings.NewReplacer("/", "_", "-", "_", ".", "_")
293+
safeEnvVar := strings.NewReplacer("/", "_", "-", "_", ".", "_", ":", "_")
285294

286295
// Check for a specific override for this binary path, less common but allows supporting
287296
// images that have multiple test binaries.

pkg/test/ginkgo/cmd_runsuite.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,17 @@ func createUnpermittedExtensionTests(unpermitted []extensions.UnpermittedExtensi
191191
if len(unpermitted) > 0 {
192192
logrus.Warnf("Found %d unpermitted extension binary(ies)", len(unpermitted))
193193

194-
msg := "extension binary not permitted by TestExtensionAdmission:\n"
194+
var msg strings.Builder
195+
msg.WriteString("extension binary not permitted by TestExtensionAdmission:\n")
195196
for _, u := range unpermitted {
196-
msg = fmt.Sprintf("%s\n - %s/%s:%s (%s)\n", msg, u.Namespace, u.ImageStream, u.Tag, u.Component)
197+
fmt.Fprintf(&msg, "\n - %s/%s:%s (%s)\n", u.Namespace, u.ImageStream, u.Tag, u.Component)
197198
logrus.Warnf(" Unpermitted: %s/%s:%s (%s)", u.Namespace, u.ImageStream, u.Tag, u.Component)
198199
}
199200

200201
testCases = append(testCases, &junitapi.JUnitTestCase{
201202
Name: testName,
202203
FailureOutput: &junitapi.FailureOutput{
203-
Output: msg,
204+
Output: msg.String(),
204205
},
205206
})
206207
}

0 commit comments

Comments
 (0)