Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STONEBLD-1735 allow creation of private repositories #846

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions deploy/crds/base/jvmbuildservice.io_jbsconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ spec:
type: string
prependTag:
type: string
private:
description: if this is true and we are automatically creating
registries then we will make it private
type: boolean
repository:
type: string
secretName:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class SetupRebuildsCommand implements Runnable {
@Inject
KubernetesClient client;

@CommandLine.Option(names = "--private-repo")
boolean privateRepo;

@Override
public void run() {

Expand All @@ -27,13 +30,15 @@ public void run() {
}
config.getSpec().setEnableRebuilds(true);
config.getSpec().setRequireArtifactVerification(true);
config.getSpec().getRegistry().set_private(privateRepo);
resource.patch(config);
} else {
config = new JBSConfig();
config.setSpec(new JBSConfigSpec());
config.getMetadata().setName(ModelConstants.JBS_CONFIG_NAME);
config.getSpec().setEnableRebuilds(true);
config.getSpec().setRequireArtifactVerification(true);
config.getSpec().getRegistry().set_private(privateRepo);
client.resource(config).create();
}
long timeout = System.currentTimeMillis() + 10000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ spec:
type: string
prependTag:
type: string
private:
description: if this is true and we are automatically creating
registries then we will make it private
type: boolean
repository:
type: string
secretName:
Expand Down
28 changes: 16 additions & 12 deletions openshift-with-appstudio-test/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,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{
{
Expand Down Expand Up @@ -897,13 +899,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{},
Expand Down
15 changes: 11 additions & 4 deletions pkg/apis/jvmbuildservice/v1alpha1/jbsconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,23 @@ type JBSConfigSpec struct {

MavenBaseLocations map[string]string `json:"mavenBaseLocations,omitempty"`

SharedRegistries []ImageRegistry `json:"sharedRegistries,omitempty"`
Registry ImageRegistry `json:"registry,omitempty"`
MavenDeployment MavenDeployment `json:"mavenDeployment,omitempty"`
SharedRegistries []ImageRegistry `json:"sharedRegistries,omitempty"`
Registry ImageRegistrySpec `json:"registry,omitempty"`
MavenDeployment MavenDeployment `json:"mavenDeployment,omitempty"`
// Deprecated: Replaced by explicit declaration of Registry above.
ImageRegistry `json:",inline,omitempty"`
CacheSettings CacheSettings `json:"cacheSettings,omitempty"`
BuildSettings BuildSettings `json:"buildSettings,omitempty"`
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 private
Private *bool `json:"private,omitempty"`
}

type JBSConfigStatus struct {
Message string `json:"message,omitempty"`
ImageRegistry *ImageRegistry `json:"imageRegistry,omitempty"`
Expand Down Expand Up @@ -134,7 +141,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"
}
Expand Down
24 changes: 23 additions & 1 deletion pkg/apis/jvmbuildservice/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion pkg/reconciler/jbsconfig/jbsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,13 +598,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.ImageVisibilityPublic
if config.Spec.Registry.Private != nil && *config.Spec.Registry.Private {
vis = imagecontroller.ImageVisibilityPrivate
}
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
Expand Down