gitops

package
v1.10.7 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package gitops is the declarative, pull-based half of Miabi's GitOps and CI/CD model. A GitSource binds a Git repo of miabi.io/v1 manifests to a workspace; the reconciler clones at a ref, renders and diffs against live state, and converges by reusing the apply engine. It adds no container plumbing.

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)
	ApplyResource(ctx context.Context, workspaceID uint, manifests []byte, opts apply.Options, kind, name string) (*apply.Result, error)
	DeleteResource(ctx context.Context, workspaceID uint, kind, name string) (*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. With cascade, the resources the project created — those carrying its gitops-source label — are torn down first in dependency-safe order. Without it they keep running, orphaned from GitOps management. Returns the teardown result so callers can show what was removed.

func (*Service) DeleteResource added in v1.6.5

func (s *Service) DeleteResource(ctx context.Context, workspaceID, id uint, kind, name string) (*apply.Result, error)

DeleteResource deletes a single live resource (kind/name) managed by a source. Under auto-sync it will be recreated on the next reconcile — the handler warns the user. Scoped to the source so a caller can't delete outside its project.

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) SetSecrets added in v1.7.3

func (s *Service) SetSecrets(v gitrepo.Secrets)

SetSecrets wires the vault, so a Git credential that references a workspace Secret (rather than storing its own copy of the token) can be resolved when a source is fetched. nil = literal credentials only.

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) SyncResource added in v1.6.5

func (s *Service) SyncResource(ctx context.Context, workspaceID, id uint, kind, name string) (*apply.Result, error)

SyncResource reconciles a single resource (kind/name) of a source — the GitOps "sync this resource" action — without touching the rest of the project. It does not update the source's overall sync status (a partial sync isn't a project sync).

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 against the source's secret.

Jump to

Keyboard shortcuts

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