Skip to content

Commit

Permalink
feat: add GitRepository kind (#63)
Browse files Browse the repository at this point in the history
* new kind from kubebuilder

Signed-off-by: Zach Aller <[email protected]>

* new kind from kubebuilder

Signed-off-by: Zach Aller <[email protected]>

* working tests

Signed-off-by: Zach Aller <[email protected]>

* no pointer

Signed-off-by: Zach Aller <[email protected]>

* update examles

Signed-off-by: Zach Aller <[email protected]>

---------

Signed-off-by: Zach Aller <[email protected]>
  • Loading branch information
zachaller authored Oct 21, 2024
1 parent bf1d6d8 commit 18d60c7
Show file tree
Hide file tree
Showing 45 changed files with 833 additions and 321 deletions.
23 changes: 16 additions & 7 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ domain: argoproj.io
layout:
- go.kubebuilder.io/v4
projectName: promoter
repo: github.com/argoproj/promoter
repo: github.com/argoproj-labs/gitops-promoter
resources:
- api:
crdVersion: v1
Expand All @@ -15,7 +15,7 @@ resources:
domain: argoproj.io
group: promoter
kind: PullRequest
path: github.com/argoproj/promoter/api/v1alpha1
path: github.com/argoproj-labs/gitops-promoter/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
Expand All @@ -24,7 +24,7 @@ resources:
domain: argoproj.io
group: promoter
kind: CommitStatus
path: github.com/argoproj/promoter/api/v1alpha1
path: github.com/argoproj-labs/gitops-promoter/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
Expand All @@ -33,7 +33,7 @@ resources:
domain: argoproj.io
group: promoter
kind: RevertCommit
path: github.com/argoproj/promoter/api/v1alpha1
path: github.com/argoproj-labs/gitops-promoter/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
Expand All @@ -42,7 +42,7 @@ resources:
domain: argoproj.io
group: promoter
kind: ProposedCommit
path: github.com/argoproj/promoter/api/v1alpha1
path: github.com/argoproj-labs/gitops-promoter/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
Expand All @@ -51,7 +51,7 @@ resources:
domain: argoproj.io
group: promoter
kind: PromotionStrategy
path: github.com/argoproj/promoter/api/v1alpha1
path: github.com/argoproj-labs/gitops-promoter/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
Expand All @@ -60,6 +60,15 @@ resources:
domain: argoproj.io
group: promoter
kind: ScmProvider
path: github.com/argoproj/promoter/api/v1alpha1
path: github.com/argoproj-labs/gitops-promoter/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: argoproj.io
group: promoter
kind: GitRepository
path: github.com/argoproj-labs/gitops-promoter/api/v1alpha1
version: v1alpha1
version: "3"
2 changes: 1 addition & 1 deletion api/v1alpha1/commitstatus_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type CommitStatusSpec struct {
// Important: Run "make" to regenerate code after modifying this file

// +kubebuilder:validation:Required
RepositoryReference *Repository `json:"repository"`
RepositoryReference NamespacedObjectReference `json:"gitRepositoryRef"`

// +kubebuilder:validation:Required
Sha string `json:"sha"`
Expand Down
9 changes: 0 additions & 9 deletions api/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ type Fake struct {
Domain string `json:"domain,omitempty"`
}

type Repository struct {
// +kubebuilder:validation:Required
Owner string `json:"owner"`
// +kubebuilder:validation:Required
Name string `json:"name"`
// +kubebuilder:validation:Required
ScmProviderRef NamespacedObjectReference `json:"scmProviderRef"`
}

type NamespacedObjectReference struct {
// +kubebuilder:validation:Required
Name string `json:"name"`
Expand Down
65 changes: 65 additions & 0 deletions api/v1alpha1/gitrepository_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Copyright 2024.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// GitRepositorySpec defines the desired state of GitRepository
type GitRepositorySpec struct {
// +kubebuilder:validation:Required
Owner string `json:"owner"`
// +kubebuilder:validation:Required
Name string `json:"name"`
// +kubebuilder:validation:Required
ScmProviderRef NamespacedObjectReference `json:"scmProviderRef"`
}

// GitRepositoryStatus defines the observed state of GitRepository
type GitRepositoryStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// GitRepository is the Schema for the gitrepositories API
type GitRepository struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec GitRepositorySpec `json:"spec,omitempty"`
Status GitRepositoryStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// GitRepositoryList contains a list of GitRepository
type GitRepositoryList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []GitRepository `json:"items"`
}

func init() {
SchemeBuilder.Register(&GitRepository{}, &GitRepositoryList{})
}
2 changes: 1 addition & 1 deletion api/v1alpha1/promotionstrategy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type PromotionStrategySpec struct {
// Important: Run "make" to regenerate code after modifying this file

// +kubebuilder:validation:Required
RepositoryReference *Repository `json:"repository"`
RepositoryReference NamespacedObjectReference `json:"gitRepositoryRef"`

// +kubebuilder:validation:Required
DryBanch string `json:"dryBranch"`
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/proposedcommit_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type ProposedCommitSpec struct {

// RepositoryReference what repository to open the PR on.
// +kubebuilder:validation:Required
RepositoryReference *Repository `json:"repository"`
RepositoryReference NamespacedObjectReference `json:"gitRepositoryRef"`

// ProposedBranch staging hydrated branch
// +kubebuilder:validation:Required
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/pullrequest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type PullRequestSpec struct {

// RepositoryReference what repository to open the PR on.
// +kubebuilder:validation:Required
RepositoryReference *Repository `json:"repository"`
RepositoryReference NamespacedObjectReference `json:"gitRepositoryRef"`
// Title is the title of the pull request.
// +kubebuilder:validation:Required
Title string `json:"title"`
Expand Down
134 changes: 96 additions & 38 deletions api/v1alpha1/zz_generated.deepcopy.go

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

7 changes: 7 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "ScmProvider")
os.Exit(1)
}
if err = (&controller.GitRepositoryReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "GitRepository")
os.Exit(1)
}
//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
Loading

0 comments on commit 18d60c7

Please sign in to comment.