gitops

package
v1.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: AGPL-3.0 Imports: 21 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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) Create

func (s *Service) Create(workspaceID uint, in Input) (*models.GitSource, error)

Create registers a new GitSource and assigns it a webhook secret.

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

func (s *Service) Diff(ctx context.Context, workspaceID, id uint) (*declarative.Plan, error)

Diff clones the source and returns the desired-vs-live plan without applying — the data behind the GitOps screen's diff viewer.

func (*Service) Get

func (s *Service) Get(workspaceID, id uint) (*models.GitSource, error)

func (*Service) IDByUID

func (s *Service) IDByUID(uid string) (uint, error)

IDByUID resolves a git source's portable uid to its numeric id.

func (*Service) List

func (s *Service) List(workspaceID uint) ([]models.GitSource, error)

func (*Service) Reconcile

func (s *Service) Reconcile(ctx context.Context, src *models.GitSource) error

Reconcile clones the source at its ref, applies the manifests, and records the resulting status on the source.

func (*Service) ReconcileAuto

func (s *Service) ReconcileAuto(ctx context.Context) error

ReconcileAuto reconciles every auto-sync source. It is the cron sweep entry point; errors on individual sources are logged, not fatal.

func (*Service) Status

func (s *Service) Status(workspaceID, id uint) (map[string]string, error)

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

func (s *Service) Sync(ctx context.Context, workspaceID, id uint) (*models.GitSource, error)

Sync reconciles a source addressed by workspace+id (manual trigger / webhook).

func (*Service) SyncByID

func (s *Service) SyncByID(ctx context.Context, id uint) error

SyncByID reconciles a source by id without workspace scoping (worker/cron).

func (*Service) Topology

func (s *Service) Topology(ctx context.Context, workspaceID, id uint) (*apply.Topology, error)

Topology clones the source and returns the resource graph (nodes + dependency edges) behind the project-detail topology view.

func (*Service) Update

func (s *Service) Update(workspaceID, id uint, in Input) (*models.GitSource, error)

Update mutates an existing GitSource's configuration.

func (*Service) VerifyWebhook

func (s *Service) VerifyWebhook(src *models.GitSource, signature string, body []byte) bool

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL