From 618011ae271bd5ef4d6a20131bab97dee4af5fec Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Thu, 14 Sep 2023 11:02:17 +1000 Subject: [PATCH] STONEBLD-1735 default to private repositories --- .../base/jvmbuildservice.io_jbsconfigs.yaml | 4 +++ .../crds/jvmbuildservice.io_jbsconfigs.yaml | 4 +++ openshift-with-appstudio-test/e2e/util.go | 28 +++++++++++-------- .../v1alpha1/jbsconfig_types.go | 14 ++++++++-- .../v1alpha1/zz_generated.deepcopy.go | 24 +++++++++++++++- pkg/reconciler/jbsconfig/jbsconfig.go | 6 +++- 6 files changed, 63 insertions(+), 17 deletions(-) diff --git a/deploy/crds/base/jvmbuildservice.io_jbsconfigs.yaml b/deploy/crds/base/jvmbuildservice.io_jbsconfigs.yaml index 237604b3fb..c940e67b46 100644 --- a/deploy/crds/base/jvmbuildservice.io_jbsconfigs.yaml +++ b/deploy/crds/base/jvmbuildservice.io_jbsconfigs.yaml @@ -115,6 +115,10 @@ spec: type: string prependTag: type: string + public: + description: if this is true and we are automatically creating + registries then we will make it public + type: boolean repository: type: string secretName: diff --git a/java-components/resource-model/src/main/resources/crds/jvmbuildservice.io_jbsconfigs.yaml b/java-components/resource-model/src/main/resources/crds/jvmbuildservice.io_jbsconfigs.yaml index 237604b3fb..c940e67b46 100644 --- a/java-components/resource-model/src/main/resources/crds/jvmbuildservice.io_jbsconfigs.yaml +++ b/java-components/resource-model/src/main/resources/crds/jvmbuildservice.io_jbsconfigs.yaml @@ -115,6 +115,10 @@ spec: type: string prependTag: type: string + public: + description: if this is true and we are automatically creating + registries then we will make it public + type: boolean repository: type: string secretName: diff --git a/openshift-with-appstudio-test/e2e/util.go b/openshift-with-appstudio-test/e2e/util.go index b89923fc6f..d29458550c 100644 --- a/openshift-with-appstudio-test/e2e/util.go +++ b/openshift-with-appstudio-test/e2e/util.go @@ -295,11 +295,13 @@ func setupConfig(t *testing.T, namespace string, hermetic bool) *testArgs { WorkerThreads: "100", RequestCPU: "10m", }, - Registry: v1alpha1.ImageRegistry{ - Host: "quay.io", - Owner: owner, - Repository: "test-images", - PrependTag: strconv.FormatInt(time.Now().UnixMilli(), 10), + Registry: v1alpha1.ImageRegistrySpec{ + ImageRegistry: v1alpha1.ImageRegistry{ + Host: "quay.io", + Owner: owner, + Repository: "test-images", + PrependTag: strconv.FormatInt(time.Now().UnixMilli(), 10), + }, }, RelocationPatterns: []v1alpha1.RelocationPatternElement{ { @@ -878,13 +880,15 @@ func setupMinikube(t *testing.T, namespace string) *testArgs { DisableTLS: true, Storage: "756Mi", }, - Registry: v1alpha1.ImageRegistry{ - Host: devIp, - Owner: owner, - Repository: "test-images", - Port: "5000", - Insecure: true, - PrependTag: strconv.FormatInt(time.Now().UnixMilli(), 10), + Registry: v1alpha1.ImageRegistrySpec{ + ImageRegistry: v1alpha1.ImageRegistry{ + Host: devIp, + Owner: owner, + Repository: "test-images", + Port: "5000", + Insecure: true, + PrependTag: strconv.FormatInt(time.Now().UnixMilli(), 10), + }, }, }, Status: v1alpha1.JBSConfigStatus{}, diff --git a/pkg/apis/jvmbuildservice/v1alpha1/jbsconfig_types.go b/pkg/apis/jvmbuildservice/v1alpha1/jbsconfig_types.go index 92718a3a06..3c5a825055 100644 --- a/pkg/apis/jvmbuildservice/v1alpha1/jbsconfig_types.go +++ b/pkg/apis/jvmbuildservice/v1alpha1/jbsconfig_types.go @@ -39,8 +39,9 @@ type JBSConfigSpec struct { MavenBaseLocations map[string]string `json:"mavenBaseLocations,omitempty"` - SharedRegistries []ImageRegistry `json:"sharedRegistries,omitempty"` - Registry ImageRegistry `json:"registry,omitempty"` + SharedRegistries []ImageRegistry `json:"sharedRegistries,omitempty"` + Registry ImageRegistrySpec `json:"registry,omitempty"` + // Deprecated: Replaced by explicit declaration of Registry above. ImageRegistry `json:",inline,omitempty"` CacheSettings CacheSettings `json:"cacheSettings,omitempty"` @@ -48,6 +49,13 @@ type JBSConfigSpec struct { RelocationPatterns []RelocationPatternElement `json:"relocationPatterns,omitempty"` } +type ImageRegistrySpec struct { + ImageRegistry `json:",inline,omitempty"` + + //if this is true and we are automatically creating registries then we will make it public + Public *bool `json:"public,omitempty"` +} + type JBSConfigStatus struct { Message string `json:"message,omitempty"` ImageRegistry *ImageRegistry `json:"imageRegistry,omitempty"` @@ -122,7 +130,7 @@ type JBSConfig struct { } func (in *JBSConfig) ImageRegistry() ImageRegistry { - ret := in.Spec.Registry + ret := in.Spec.Registry.ImageRegistry if ret.Host == "" { ret.Host = "quay.io" } diff --git a/pkg/apis/jvmbuildservice/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/jvmbuildservice/v1alpha1/zz_generated.deepcopy.go index 032d6b0ec1..eaac32c6ad 100644 --- a/pkg/apis/jvmbuildservice/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/jvmbuildservice/v1alpha1/zz_generated.deepcopy.go @@ -474,6 +474,28 @@ func (in *ImageRegistry) DeepCopy() *ImageRegistry { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ImageRegistrySpec) DeepCopyInto(out *ImageRegistrySpec) { + *out = *in + out.ImageRegistry = in.ImageRegistry + if in.Public != nil { + in, out := &in.Public, &out.Public + *out = new(bool) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ImageRegistrySpec. +func (in *ImageRegistrySpec) DeepCopy() *ImageRegistrySpec { + if in == nil { + return nil + } + out := new(ImageRegistrySpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *JBSConfig) DeepCopyInto(out *JBSConfig) { *out = *in @@ -555,7 +577,7 @@ func (in *JBSConfigSpec) DeepCopyInto(out *JBSConfigSpec) { *out = make([]ImageRegistry, len(*in)) copy(*out, *in) } - out.Registry = in.Registry + in.Registry.DeepCopyInto(&out.Registry) out.ImageRegistry = in.ImageRegistry out.CacheSettings = in.CacheSettings out.BuildSettings = in.BuildSettings diff --git a/pkg/reconciler/jbsconfig/jbsconfig.go b/pkg/reconciler/jbsconfig/jbsconfig.go index c0f24b4462..4397d5a4ee 100644 --- a/pkg/reconciler/jbsconfig/jbsconfig.go +++ b/pkg/reconciler/jbsconfig/jbsconfig.go @@ -595,13 +595,17 @@ func (r *ReconcilerJBSConfig) cacheDeployment(ctx context.Context, log logr.Logg func (r *ReconcilerJBSConfig) handleNoOwnerSpecified(ctx context.Context, log logr.Logger, config *v1alpha1.JBSConfig) error { + vis := imagecontroller.ImageVisibilityPrivate + if config.Spec.Registry.Public != nil && *config.Spec.Registry.Public { + vis = imagecontroller.ImageVisibilityPublic + } repo := imagecontroller.ImageRepository{} err := r.client.Get(ctx, types.NamespacedName{Namespace: config.Namespace, Name: v1alpha1.DefaultImageSecretName}, &repo) if err != nil { if errors.IsNotFound(err) { repo.Name = v1alpha1.DefaultImageSecretName repo.Namespace = config.Namespace - repo.Spec.Image.Visibility = imagecontroller.ImageVisibilityPublic + repo.Spec.Image.Visibility = vis err := controllerutil.SetOwnerReference(config, &repo, r.scheme) if err != nil { return err