Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Manabu Mccloskey <[email protected]>
  • Loading branch information
nabuskey committed Nov 16, 2023
1 parent ab7a85c commit 6538ae2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions pkg/controllers/gitrepository/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ const (
gitCommitAuthorEmail = "[email protected]"
)

type ClientFN func(url string, options ...gitea.ClientOption) (GiteaClient, error)
type GiteaClientFunc func(url string, options ...gitea.ClientOption) (GiteaClient, error)

func NewGiteaClient(url string, options ...gitea.ClientOption) (GiteaClient, error) {
return gitea.NewClient(url, options...)
}

type RepositoryReconciler struct {
client.Client
GiteaClientFN ClientFN
Recorder record.EventRecorder
Scheme *runtime.Scheme
GiteaClientFunc GiteaClientFunc
Recorder record.EventRecorder
Scheme *runtime.Scheme
}

func getRepositoryName(repo v1alpha1.GitRepository) string {
Expand Down Expand Up @@ -108,7 +108,7 @@ func (r *RepositoryReconciler) postProcessReconcile(ctx context.Context, req ctr
func (r *RepositoryReconciler) reconcileGitRepo(ctx context.Context, repo *v1alpha1.GitRepository) (ctrl.Result, error) {
logger := log.FromContext(ctx)
logger.Info("reconciling", "name", repo.Name, "dir", repo.Spec.Source)
giteaClient, err := r.GiteaClientFN(repo.Spec.GiteaURL)
giteaClient, err := r.GiteaClientFunc(repo.Spec.GiteaURL)
if err != nil {
return ctrl.Result{Requeue: true, RequeueAfter: requeueTime}, fmt.Errorf("failed to get gitea client: %w", err)
}
Expand Down Expand Up @@ -256,14 +256,14 @@ func getEmbedded(name string) ([][]byte, error) {
}
}

func writeRepoContents(repo *v1alpha1.GitRepository, tempDir string) error {
func writeRepoContents(repo *v1alpha1.GitRepository, dstPath string) error {
if repo.Spec.Source.EmbeddedAppName != "" {
resources, err := getEmbedded(repo.Spec.Source.EmbeddedAppName)
if err != nil {
return fmt.Errorf("getting embedded resource; %w", err)
}
for i := range resources {
filePath := filepath.Join(tempDir, fmt.Sprintf("resource%d.yaml", i))
filePath := filepath.Join(dstPath, fmt.Sprintf("resource%d.yaml", i))
err = os.WriteFile(filePath, resources[i], 0644)
if err != nil {
return fmt.Errorf("writing embedded resource; %w", err)
Expand All @@ -272,7 +272,7 @@ func writeRepoContents(repo *v1alpha1.GitRepository, tempDir string) error {
return nil
}

err := util.CopyDirectory(repo.Spec.Source.Path, tempDir)
err := util.CopyDirectory(repo.Spec.Source.Path, dstPath)
if err != nil {
return fmt.Errorf("copying files: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/controllers/gitrepository/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func TestGitRepositoryContentReconcile(t *testing.T) {
t.Run("files modified", func(t *testing.T) {
reconciler := RepositoryReconciler{
Client: fake.NewClientBuilder().Build(),
GiteaClientFN: func(url string, options ...gitea.ClientOption) (GiteaClient, error) {
GiteaClientFunc: func(url string, options ...gitea.ClientOption) (GiteaClient, error) {
return mockGitea{}, nil
},
}
Expand Down Expand Up @@ -251,7 +251,7 @@ func TestGitRepositoryContentReconcileEmbedded(t *testing.T) {
t.Run("should sync embedded", func(t *testing.T) {
reconciler := RepositoryReconciler{
Client: fake.NewClientBuilder().Build(),
GiteaClientFN: func(url string, options ...gitea.ClientOption) (GiteaClient, error) {
GiteaClientFunc: func(url string, options ...gitea.ClientOption) (GiteaClient, error) {
return mockGitea{}, nil
},
}
Expand Down Expand Up @@ -343,8 +343,8 @@ func TestGitRepositoryReconcile(t *testing.T) {
v := cases[k]
t.Run(k, func(t *testing.T) {
reconciler := RepositoryReconciler{
Client: fake.NewClientBuilder().Build(),
GiteaClientFN: v.giteaClient,
Client: fake.NewClientBuilder().Build(),
GiteaClientFunc: v.giteaClient,
}
_, err := reconciler.reconcileGitRepo(ctx, &v.input)
if v.expect.err == nil && err != nil {
Expand Down

0 comments on commit 6538ae2

Please sign in to comment.