Skip to content
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM alpine:3.21
RUN apk add --no-cache tzdata ca-certificates
RUN apk add --no-cache tzdata ca-certificates curl
WORKDIR /
COPY gmc gmc
USER nobody
Expand Down
41 changes: 41 additions & 0 deletions pkg/master/cloner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package master

import (
"context"
"net/url"
"os"
"path/filepath"

"github.com/fluxcd/pkg/git"
"github.com/fluxcd/pkg/git/repository"
"github.com/sirupsen/logrus"
)

type Cloner interface {
Clone(ctx context.Context, url string, cloneOpts repository.CloneConfig) (*git.Commit, error)
Close()
}

type testCloner struct {
dir string
}

func (tc *testCloner) Clone(ctx context.Context, URL string, cloneOpts repository.CloneConfig) (*git.Commit, error) {

u, err := url.Parse(URL)
if err != nil {
return nil, err
}
cwd, err := os.Getwd()
if err != nil {
return nil, err
}

from := filepath.Join(cwd, u.Path)
logrus.Infof("testCloner: copy %s to %s", from, tc.dir)
err = os.CopyFS(tc.dir, os.DirFS(from))
return nil, err
}
func (tc *testCloner) Close() {

}
49 changes: 1 addition & 48 deletions pkg/master/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ import (
"k8s.io/apimachinery/pkg/labels"
)

/*
TODO
Think about HA?
HA
* clients connect to prefered master
* admin command knows all masters
* do we want leaderelection so only one syncs from git? Probably!
* how to ensure clients fetches from the current leader?

*/

type websocketRequestResponse struct {
list map[string]chan *websocketRequest
mutex *sync.RWMutex
Expand Down Expand Up @@ -264,13 +253,6 @@ func (m *Master) run(ctx context.Context) error {
}
}

// if ref := obj.Spec.Reference; ref != nil {
// https://github.com/fluxcd/source-controller/blob/16fed8995d1f5ba818697220fd2020f78e2cc630/controllers/gitrepository_controller.go#L733
// cloneOpts.Branch = ref.Branch
// cloneOpts.Commit = ref.Commit
// cloneOpts.Tag = ref.Tag
// cloneOpts.SemVer = ref.SemVer
// }
}

func (m *Master) stateRunner(ctx context.Context, ch chan *types.Machine, websocketCh chan *websocketRequest, machineUpd chan machineUpdate) {
Expand Down Expand Up @@ -474,7 +456,7 @@ func (m *Master) handleRequest(ctx context.Context, machines map[string]*types.M
machineUpdateCh <- machineUpdate{Machine: machine, Source: protocol.ManualSource}

case "agent-aqure-lock":
if admin, _ := sess.Get("allowed"); !admin.(bool) {
if allowed, _ := sess.Get("allowed"); !allowed.(bool) {
return fmt.Errorf("agent-aqure-lock permission denied")
}
l := &protocol.AgentLock{}
Expand Down Expand Up @@ -566,35 +548,6 @@ func sendIsLast(sess *melody.Session, reqID string) {
}
}

type Cloner interface {
Clone(ctx context.Context, url string, cloneOpts repository.CloneConfig) (*git.Commit, error)
Close()
}

type testCloner struct {
dir string
}

func (tc *testCloner) Clone(ctx context.Context, URL string, cloneOpts repository.CloneConfig) (*git.Commit, error) {

u, err := url.Parse(URL)
if err != nil {
return nil, err
}
cwd, err := os.Getwd()
if err != nil {
return nil, err
}

from := filepath.Join(cwd, u.Path)
logrus.Infof("testCloner: copy %s to %s", from, tc.dir)
err = os.CopyFS(tc.dir, os.DirFS(from))
return nil, err
}
func (tc *testCloner) Close() {

}

func (m *Master) clone(ctx context.Context, authOpts *git.AuthOptions, cloneOpts repository.CloneConfig, manifestCh chan machineUpdate) error {
dir, err := os.MkdirTemp("", "gmc")
if err != nil {
Expand Down