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

add deploymentRepositoryRef and scaffoldsRepositoryRef #1829

Merged
merged 1 commit into from
Jan 31, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,19 @@ spec:
format: int64
type: integer
type: object
deploymentRepositoryRef:
description: pointer to the deployment GIT repository to use
properties:
name:
description: Name is a resource name.
type: string
namespace:
description: Namespace is a resource namespace.
type: string
required:
- name
- namespace
type: object
logging:
description: Settings for connections to log aggregation datastores
properties:
Expand Down Expand Up @@ -627,6 +640,19 @@ spec:
required:
- host
type: object
scaffoldsRepositoryRef:
description: pointer to the Scaffolds GIT repository to use
properties:
name:
description: Name is a resource name.
type: string
namespace:
description: Namespace is a resource namespace.
type: string
required:
- name
- namespace
type: object
stacks:
description: Stacks global configuration for stack execution
properties:
Expand Down
8 changes: 8 additions & 0 deletions go/controller/api/v1alpha1/deploymentsettings_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ type DeploymentSettingsSpec struct {
//
// +kubebuilder:validation:Optional
Cost *CostSettings `json:"cost,omitempty"`

// pointer to the deployment GIT repository to use
// +kubebuilder:validation:Optional
DeploymentRepositoryRef *NamespacedName `json:"deploymentRepositoryRef,omitempty"`

// pointer to the Scaffolds GIT repository to use
// +kubebuilder:validation:Optional
ScaffoldsRepositoryRef *NamespacedName `json:"scaffoldsRepositoryRef,omitempty"`
}

type LoggingSettings struct {
Expand Down
10 changes: 10 additions & 0 deletions go/controller/api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,19 @@ spec:
format: int64
type: integer
type: object
deploymentRepositoryRef:
description: pointer to the deployment GIT repository to use
properties:
name:
description: Name is a resource name.
type: string
namespace:
description: Namespace is a resource namespace.
type: string
required:
- name
- namespace
type: object
logging:
description: Settings for connections to log aggregation datastores
properties:
Expand Down Expand Up @@ -627,6 +640,19 @@ spec:
required:
- host
type: object
scaffoldsRepositoryRef:
description: pointer to the Scaffolds GIT repository to use
properties:
name:
description: Name is a resource name.
type: string
namespace:
description: Namespace is a resource namespace.
type: string
required:
- name
- namespace
type: object
stacks:
description: Stacks global configuration for stack execution
properties:
Expand Down
8 changes: 8 additions & 0 deletions go/controller/internal/controller/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,11 @@ func defaultErrMessage(err error, defaultMessage string) string {
func notFoundOrReadyErrorMessage(err error) string {
return fmt.Sprintf("Referenced object is either not found or not ready, found error: %s", err.Error())
}

func getGitRepoID(ctx context.Context, c runtimeclient.Client, namespacedName v1alpha1.NamespacedName) (*string, error) {
gitRepo := &v1alpha1.GitRepository{}
if err := c.Get(ctx, types.NamespacedName{Name: namespacedName.Name, Namespace: namespacedName.Namespace}, gitRepo); err != nil {
return nil, err
}
return gitRepo.Status.ID, nil
}
26 changes: 26 additions & 0 deletions go/controller/internal/controller/deploymentsettings_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ func (r *DeploymentSettingsReconciler) genDeploymentSettingsAttr(ctx context.Con
if settings.Spec.Stacks.ConnectionRef != nil {
connection := &v1alpha1.ScmConnection{}
if err := r.Get(ctx, types.NamespacedName{Name: settings.Spec.Stacks.ConnectionRef.Name, Namespace: settings.Spec.Stacks.ConnectionRef.Namespace}, connection); err != nil {
if errors.IsNotFound(err) {
return nil, operrors.ErrReferenceNotFound
}
return nil, err
}
connectionID = connection.Status.ID
Expand All @@ -229,6 +232,29 @@ func (r *DeploymentSettingsReconciler) genDeploymentSettingsAttr(ctx context.Con
attr.CreateBindings = policyBindings(settings.Spec.Bindings.Create)
attr.GitBindings = policyBindings(settings.Spec.Bindings.Git)
}

if settings.Spec.DeploymentRepositoryRef != nil {
id, err := getGitRepoID(ctx, r.Client, *settings.Spec.DeploymentRepositoryRef)
if err != nil {
if errors.IsNotFound(err) {
return nil, operrors.ErrReferenceNotFound
}
return nil, err
}
attr.DeployerRepositoryID = id
}

if settings.Spec.ScaffoldsRepositoryRef != nil {
id, err := getGitRepoID(ctx, r.Client, *settings.Spec.ScaffoldsRepositoryRef)
if err != nil {
if errors.IsNotFound(err) {
return nil, operrors.ErrReferenceNotFound
}
return nil, err
}
attr.ArtifactRepositoryID = id
}

return attr, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,19 @@ spec:
format: int64
type: integer
type: object
deploymentRepositoryRef:
description: pointer to the deployment GIT repository to use
properties:
name:
description: Name is a resource name.
type: string
namespace:
description: Namespace is a resource namespace.
type: string
required:
- name
- namespace
type: object
logging:
description: Settings for connections to log aggregation datastores
properties:
Expand Down Expand Up @@ -627,6 +640,19 @@ spec:
required:
- host
type: object
scaffoldsRepositoryRef:
description: pointer to the Scaffolds GIT repository to use
properties:
name:
description: Name is a resource name.
type: string
namespace:
description: Namespace is a resource namespace.
type: string
required:
- name
- namespace
type: object
stacks:
description: Stacks global configuration for stack execution
properties:
Expand Down
Loading