Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.

Commit 1a2e13a

Browse files
authored
feat: add repository object (#13)
* feat: add repository object This change adds the ability to create repositories and pull requests for different providers. * updated tiltfile and added github repositroy support * added adopt or fail options for existing repositories
1 parent 9df3686 commit 1a2e13a

33 files changed

+1074
-41
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN go mod download
1313

1414
# Copy the go source
1515
COPY main.go main.go
16-
COPY api/ api/
16+
COPY apis/ apis/
1717
COPY controllers/ controllers/
1818
COPY pkg/ pkg/
1919

PROJECT

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
15
domain: ocm.software
26
layout:
37
- go.kubebuilder.io/v3
8+
multigroup: true
49
projectName: git-controller
510
repo: github.com/open-component-model/git-controller
611
resources:
@@ -11,6 +16,15 @@ resources:
1116
domain: ocm.software
1217
group: delivery
1318
kind: Sync
14-
path: github.com/open-component-model/git-controller/api/v1alpha1
19+
path: github.com/open-component-model/git-controller/apis/delivery/v1alpha1
20+
version: v1alpha1
21+
- api:
22+
crdVersion: v1
23+
namespaced: true
24+
controller: true
25+
domain: ocm.software
26+
group: mpas
27+
kind: Repository
28+
path: github.com/open-component-model/git-controller/apis/mpas/v1alpha1
1529
version: v1alpha1
1630
version: "3"

Tiltfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ local_resource(
3939
"main.go",
4040
"go.mod",
4141
"go.sum",
42-
"api",
42+
"apis",
4343
"controllers",
4444
"pkg",
4545
],

api/v1alpha1/condition_types.go renamed to apis/delivery/v1alpha1/condition_types.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Copyright 2022.
21
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors.
32
//
43
// SPDX-License-Identifier: Apache-2.0
@@ -12,7 +11,7 @@ const (
1211
// SnapshotGetFailedReason is used when the needed snapshot does not exist.
1312
SnapshotGetFailedReason = "SnapshotGetFailed"
1413

15-
// AuthenticateGetFailedReason is used when the needed authentication does not exist.
14+
// CredentialsNotFoundReason is used when the needed authentication does not exist.
1615
CredentialsNotFoundReason = "CredentialsNotFound"
1716

1817
// GitRepositoryPushFailedReason is used when the needed pushing to a git repository failed.

api/v1alpha1/groupversion_info.go renamed to apis/delivery/v1alpha1/groupversion_info.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Copyright 2022.
21
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors.
32
//
43
// SPDX-License-Identifier: Apache-2.0

api/v1alpha1/sync_types.go renamed to apis/delivery/v1alpha1/sync_types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Copyright 2022.
21
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors.
32
//
43
// SPDX-License-Identifier: Apache-2.0
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package v1alpha1
6+
7+
const (
8+
// RepositoryCreateFailedReason is used when we fail to create a Repository.
9+
RepositoryCreateFailedReason = "RepositoryCreateFailed"
10+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
// Package v1alpha1 contains API Schema definitions for the mpas v1alpha1 API group
6+
// +kubebuilder:object:generate=true
7+
// +groupName=mpas.ocm.software
8+
package v1alpha1
9+
10+
import (
11+
"k8s.io/apimachinery/pkg/runtime/schema"
12+
"sigs.k8s.io/controller-runtime/pkg/scheme"
13+
)
14+
15+
var (
16+
// GroupVersion is group version used to register these objects
17+
GroupVersion = schema.GroupVersion{Group: "mpas.ocm.software", Version: "v1alpha1"}
18+
19+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
20+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
21+
22+
// AddToScheme adds the types in this group-version to the given scheme.
23+
AddToScheme = SchemeBuilder.AddToScheme
24+
)
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package v1alpha1
6+
7+
import (
8+
"time"
9+
10+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
)
12+
13+
// SecretRef is a reference to a secret in the same namespace as the referencing object.
14+
type SecretRef struct {
15+
Name string `json:"name"`
16+
}
17+
18+
// Credentials contains ways of authenticating the creation of a repository.
19+
type Credentials struct {
20+
SecretRef SecretRef `json:"secretRef"`
21+
}
22+
23+
// ExistingRepositoryPolicy defines what to do in case a requested repository already exists.
24+
type ExistingRepositoryPolicy string
25+
26+
var (
27+
// ExistingRepositoryPolicyAdopt will use the repository if it exists.
28+
ExistingRepositoryPolicyAdopt ExistingRepositoryPolicy = "adopt"
29+
// ExistingRepositoryPolicyFail will fail if the requested repository already exists.
30+
ExistingRepositoryPolicyFail ExistingRepositoryPolicy = "fail"
31+
)
32+
33+
// RepositorySpec defines the desired state of Repository
34+
type RepositorySpec struct {
35+
//+required
36+
Provider string `json:"provider"`
37+
//+required
38+
Owner string `json:"owner"`
39+
//+required
40+
RepositoryName string `json:"repositoryName"`
41+
//+required
42+
Credentials Credentials `json:"credentials"`
43+
44+
//+optional
45+
Interval metav1.Duration `json:"interval,omitempty"`
46+
//+optional
47+
//+kubebuilder:default:=private
48+
Visibility string `json:"visibility,omitempty"`
49+
//+kubebuilder:default:=true
50+
IsOrganization bool `json:"isOrganization,omitempty"`
51+
//+optional
52+
Domain string `json:"domain,omitempty"`
53+
//+optional
54+
Maintainers []string `json:"maintainers,omitempty"`
55+
//+optional
56+
//+kubebuilder:default:=true
57+
AutomaticPullRequestCreation bool `json:"automaticPullRequestCreation,omitempty"`
58+
//+optional
59+
//+kubebuilder:default:=adopt
60+
//+kubebuilder:validation:Enum=adopt;fail
61+
ExistingRepositoryPolicy ExistingRepositoryPolicy `json:"existingRepositoryPolicy,omitempty"`
62+
}
63+
64+
// RepositoryStatus defines the observed state of Repository
65+
type RepositoryStatus struct {
66+
// ObservedGeneration is the last reconciled generation.
67+
// +optional
68+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
69+
70+
// +optional
71+
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status",description=""
72+
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].message",description=""
73+
Conditions []metav1.Condition `json:"conditions,omitempty"`
74+
}
75+
76+
// GetConditions returns the conditions of the ComponentVersion.
77+
func (in *Repository) GetConditions() []metav1.Condition {
78+
return in.Status.Conditions
79+
}
80+
81+
// SetConditions sets the conditions of the ComponentVersion.
82+
func (in *Repository) SetConditions(conditions []metav1.Condition) {
83+
in.Status.Conditions = conditions
84+
}
85+
86+
// GetRequeueAfter returns the duration after which the ComponentVersion must be
87+
// reconciled again.
88+
func (in Repository) GetRequeueAfter() time.Duration {
89+
return in.Spec.Interval.Duration
90+
}
91+
92+
//+kubebuilder:object:root=true
93+
//+kubebuilder:subresource:status
94+
95+
// Repository is the Schema for the repositories API
96+
type Repository struct {
97+
metav1.TypeMeta `json:",inline"`
98+
metav1.ObjectMeta `json:"metadata,omitempty"`
99+
100+
Spec RepositorySpec `json:"spec,omitempty"`
101+
Status RepositoryStatus `json:"status,omitempty"`
102+
}
103+
104+
//+kubebuilder:object:root=true
105+
106+
// RepositoryList contains a list of Repository
107+
type RepositoryList struct {
108+
metav1.TypeMeta `json:",inline"`
109+
metav1.ListMeta `json:"metadata,omitempty"`
110+
Items []Repository `json:"items"`
111+
}
112+
113+
func init() {
114+
SchemeBuilder.Register(&Repository{}, &RepositoryList{})
115+
}

0 commit comments

Comments
 (0)