Skip to content

Commit

Permalink
use git providers (#205)
Browse files Browse the repository at this point in the history
Signed-off-by: Manabu McCloskey <[email protected]>
  • Loading branch information
nabuskey authored May 13, 2024
1 parent 8822d97 commit c96f4ef
Show file tree
Hide file tree
Showing 16 changed files with 742 additions and 222 deletions.
26 changes: 20 additions & 6 deletions api/v1alpha1/gitrepository_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
GitProviderGitea = "gitea"
GitProviderGitHub = "github"
GiteaAdminUserName = "giteaAdmin"
)

type GitRepositorySpec struct {
// +kubebuilder:validation:Optional
Customization PackageCustomization `json:"customization,omitempty"`
// GitURL is the base URL of Git server used for API calls.
// +kubebuilder:validation:Required
// +kubebuilder:validation:Pattern=`^https?:\/\/.+$`
GitURL string `json:"gitURL"`
// InternalGitURL is the base URL of Git server accessible within the cluster only.
InternalGitURL string `json:"internalGitURL"`
// SecretRef is the reference to secret that contain Git server credentials
// +kubebuilder:validation:Optional
SecretRef SecretReference `json:"secretRef"`
Source GitRepositorySource `json:"source,omitempty"`
Provider Provider `json:"provider"`
}

type GitRepositorySource struct {
Expand All @@ -33,6 +34,19 @@ type GitRepositorySource struct {
Type string `json:"type"`
}

type Provider struct {
// +kubebuilder:validation:Enum:=gitea;github
// +kubebuilder:validation:Required
Name string `json:"name"`
// GitURL is the base URL of Git server used for API calls.
// +kubebuilder:validation:Required
// +kubebuilder:validation:Pattern=`^https?:\/\/.+$`
GitURL string `json:"gitURL"`
// InternalGitURL is the base URL of Git server accessible within the cluster only.
InternalGitURL string `json:"internalGitURL"`
OrganizationName string `json:"organizationName"`
}

type SecretReference struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
Expand Down
16 changes: 16 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/go-git/go-git/v5 v5.10.0
github.com/go-logr/logr v1.4.1
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v61 v61.0.0
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.9.0
k8s.io/api v0.29.1
Expand Down Expand Up @@ -56,6 +57,7 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20230323073829-e72429f035bd // indirect
github.com/google/safetext v0.0.0-20220905092116-b49f7bc46da2 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,15 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v61 v61.0.0 h1:VwQCBwhyE9JclCI+22/7mLB1PuU9eowCXKY5pNlu1go=
github.com/google/go-github/v61 v61.0.0/go.mod h1:0WR+KmsWX75G2EbpyGsGmradjo3IiciuI4BmdVCobQY=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
Expand Down
10 changes: 7 additions & 3 deletions pkg/controllers/custompackage/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,13 @@ func (r *Reconciler) reconcileGitRepo(ctx context.Context, resource *v1alpha1.Cu
Type: "local",
Path: absPath,
},
GitURL: resource.Spec.GitServerURL,
InternalGitURL: resource.Spec.InternalGitServeURL,
SecretRef: resource.Spec.GitServerAuthSecretRef,
Provider: v1alpha1.Provider{
Name: v1alpha1.GitProviderGitea,
GitURL: resource.Spec.GitServerURL,
InternalGitURL: resource.Spec.InternalGitServeURL,
OrganizationName: v1alpha1.GiteaAdminUserName,
},
SecretRef: resource.Spec.GitServerAuthSecretRef,
}

return nil
Expand Down
10 changes: 8 additions & 2 deletions pkg/controllers/custompackage/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

argov1alpha1 "github.com/cnoe-io/argocd-api/api/argo/application/v1alpha1"
"github.com/cnoe-io/idpbuilder/api/v1alpha1"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -171,10 +172,15 @@ func TestReconcileCustomPkg(t *testing.T) {
Type: "local",
Path: p,
},
GitURL: "https://cnoe.io",
InternalGitURL: "http://internal.cnoe.io",
Provider: v1alpha1.Provider{
Name: v1alpha1.GitProviderGitea,
GitURL: "https://cnoe.io",
InternalGitURL: "http://internal.cnoe.io",
OrganizationName: v1alpha1.GiteaAdminUserName,
},
},
}
assert.Equal(t, repo.Spec, expectedRepo.Spec)
ok := reflect.DeepEqual(repo.Spec, expectedRepo.Spec)
if !ok {
t.Fatalf("expected spec does not match")
Expand Down
Loading

0 comments on commit c96f4ef

Please sign in to comment.