|
| 1 | +package e2e |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + corev1 "k8s.io/api/core/v1" |
| 7 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 8 | + |
| 9 | + operatorapi "github.com/openshift/api/operator/v1" |
| 10 | + |
| 11 | + imageregistryv1 "github.com/openshift/cluster-image-registry-operator/pkg/apis/imageregistry/v1" |
| 12 | + "github.com/openshift/cluster-image-registry-operator/test/framework" |
| 13 | +) |
| 14 | + |
| 15 | +func TestReadOnly(t *testing.T) { |
| 16 | + client := framework.MustNewClientset(t, nil) |
| 17 | + |
| 18 | + defer framework.MustRemoveImageRegistry(t, client) |
| 19 | + |
| 20 | + cr := &imageregistryv1.Config{ |
| 21 | + TypeMeta: metav1.TypeMeta{ |
| 22 | + APIVersion: imageregistryv1.SchemeGroupVersion.String(), |
| 23 | + Kind: "Config", |
| 24 | + }, |
| 25 | + ObjectMeta: metav1.ObjectMeta{ |
| 26 | + Name: imageregistryv1.ImageRegistryResourceName, |
| 27 | + }, |
| 28 | + Spec: imageregistryv1.ImageRegistrySpec{ |
| 29 | + ManagementState: operatorapi.Managed, |
| 30 | + Storage: imageregistryv1.ImageRegistryConfigStorage{ |
| 31 | + Filesystem: &imageregistryv1.ImageRegistryConfigStorageFilesystem{ |
| 32 | + VolumeSource: corev1.VolumeSource{ |
| 33 | + EmptyDir: &corev1.EmptyDirVolumeSource{}, |
| 34 | + }, |
| 35 | + }, |
| 36 | + }, |
| 37 | + ReadOnly: true, |
| 38 | + Replicas: 1, |
| 39 | + }, |
| 40 | + } |
| 41 | + framework.MustDeployImageRegistry(t, client, cr) |
| 42 | + framework.MustEnsureImageRegistryIsAvailable(t, client) |
| 43 | + framework.MustEnsureInternalRegistryHostnameIsSet(t, client) |
| 44 | + framework.MustEnsureClusterOperatorStatusIsSet(t, client) |
| 45 | + framework.MustEnsureOperatorIsNotHotLooping(t, client) |
| 46 | + |
| 47 | + deploy, err := client.Deployments(imageregistryv1.ImageRegistryOperatorNamespace).Get(imageregistryv1.ImageRegistryName, metav1.GetOptions{}) |
| 48 | + if err != nil { |
| 49 | + t.Fatal(err) |
| 50 | + } |
| 51 | + found := false |
| 52 | + for _, env := range deploy.Spec.Template.Spec.Containers[0].Env { |
| 53 | + if env.Name == "REGISTRY_STORAGE_MAINTENANCE_READONLY" { |
| 54 | + if expected := "{enabled: true}"; env.Value != expected { |
| 55 | + t.Errorf("%s: got %q, want %q", env.Name, env.Value, expected) |
| 56 | + } else { |
| 57 | + found = true |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | + if !found { |
| 62 | + framework.DumpObject(t, "deployment", deploy) |
| 63 | + t.Error("environment variable REGISTRY_STORAGE_MAINTENANCE_READONLY_ENABLED=true is not found") |
| 64 | + } |
| 65 | +} |
0 commit comments