Documentation
¶
Overview ¶
Package gitops is the declarative, pull-based half of Miabi's GitOps & CI/CD model. A GitSource binds a Git repo of miabi.io/v1 manifests to a workspace; the reconciler clones at a ref, renders + diffs against live state, and converges by reusing the apply engine (Git → desired → existing reconciler → Docker). It adds no container plumbing of its own.
Index ¶
- Variables
- type Applier
- type Input
- type Service
- func (s *Service) Create(workspaceID uint, in Input) (*models.GitSource, error)
- func (s *Service) Delete(ctx context.Context, workspaceID, id uint, cascade bool) (*apply.Result, error)
- func (s *Service) Diff(ctx context.Context, workspaceID, id uint) (*declarative.Plan, error)
- func (s *Service) Get(workspaceID, id uint) (*models.GitSource, error)
- func (s *Service) IDByUID(uid string) (uint, error)
- func (s *Service) List(workspaceID uint) ([]models.GitSource, error)
- func (s *Service) Reconcile(ctx context.Context, src *models.GitSource) error
- func (s *Service) ReconcileAuto(ctx context.Context) error
- func (s *Service) Status(workspaceID, id uint) (map[string]string, error)
- func (s *Service) Sync(ctx context.Context, workspaceID, id uint) (*models.GitSource, error)
- func (s *Service) SyncByID(ctx context.Context, id uint) error
- func (s *Service) Topology(ctx context.Context, workspaceID, id uint) (*apply.Topology, error)
- func (s *Service) Update(workspaceID, id uint, in Input) (*models.GitSource, error)
- func (s *Service) VerifyWebhook(src *models.GitSource, signature string, body []byte) bool
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("git source not found") ErrNameTaken = errors.New("a git source with this name already exists") ErrNameRequired = errors.New("name is required") ErrURLRequired = errors.New("select a git repository (or provide a repository URL)") ErrRepoNotFound = errors.New("git repository not found") )
Functions ¶
This section is empty.
Types ¶
type Applier ¶
type Applier interface {
Apply(ctx context.Context, workspaceID uint, manifests []byte, opts apply.Options) (*apply.Result, error)
Teardown(ctx context.Context, workspaceID uint, sourceID string) (*apply.Result, error)
Plan(ctx context.Context, workspaceID uint, manifests []byte, opts apply.Options) (*declarative.Plan, *declarative.ResourceSet, error)
Topology(ctx context.Context, workspaceID uint, manifests []byte, opts apply.Options) (*apply.Topology, error)
LiveTopology(ctx context.Context, workspaceID uint, syncError string) (*apply.Topology, error)
LiveStatus(workspaceID uint) map[string]string
}
Applier is the subset of the apply engine the reconciler drives, kept as an interface so the package stays testable.
type Input ¶
type Input struct {
Name string
DisplayName string
RepoURL string
Ref string
Path string
GitRepositoryID *uint
SyncPolicy models.GitSyncPolicy
Prune bool
SelfHeal bool
AllowEmpty bool
}
Input is the create/update payload for a GitSource. Name is the desired unique slug handle; DisplayName is the free-text label (falls back to Name when blank).
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service manages GitSource bindings and reconciles them.
func NewService ¶
func NewService(repo *repositories.GitSourceRepository, gitRepos *repositories.GitRepoRepository, applier Applier) *Service
NewService wires the GitOps service.
func (*Service) Delete ¶
func (s *Service) Delete(ctx context.Context, workspaceID, id uint, cascade bool) (*apply.Result, error)
Delete removes a GitOps project. When cascade is set, the resources the project created (those carrying its gitops-source label) are torn down first, in dependency-safe order, before the source row is removed. Without cascade the resources are left running (orphaned from GitOps management). Returns the teardown result (nil when cascade is off) so callers can show which resources were removed and any that failed.
func (*Service) Diff ¶
Diff clones the source and returns the desired-vs-live plan without applying — the data behind the GitOps screen's diff viewer.
func (*Service) Reconcile ¶
Reconcile clones the source at its ref, applies the manifests, and records the resulting status on the source.
func (*Service) ReconcileAuto ¶
ReconcileAuto reconciles every auto-sync source. It is the cron sweep entry point; errors on individual sources are logged, not fatal.
func (*Service) Status ¶
Status returns the live runtime status of managed resources, keyed by topology node key. Cheap (no clone) so the detail page can poll it.
func (*Service) Sync ¶
Sync reconciles a source addressed by workspace+id (manual trigger / webhook).
func (*Service) SyncByID ¶
SyncByID reconciles a source by id without workspace scoping (worker/cron).
func (*Service) Topology ¶
Topology clones the source and returns the resource graph (nodes + dependency edges) behind the project-detail topology view.
func (*Service) VerifyWebhook ¶
VerifyWebhook checks an inbound push webhook's HMAC-SHA256 signature against the source's secret (GitHub's X-Hub-Signature-256 scheme). A bare secret match (GitLab's X-Gitlab-Token) is also accepted.