orders

package
v0.32.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package orders is the client of machinery-order-service's REST API (docs/adr/0002-order-through-the-order-service.md): orders go through the service, which renders with the caller's token and opens the pull request with its own GitHub identity. claims never touches git for them.

Index

Constants

This section is empty.

Variables

View Source
var Final = []string{"Ready", "Failed", "Cancelled", "Deleted"}

Final phases: nothing more happens to the order without someone acting.

Functions

func IsFinal

func IsFinal(phase string) bool

IsFinal reports whether phase is one of Final.

Types

type AutoMerge added in v0.29.0

type AutoMerge struct {
	Method string          `json:"method,omitempty"`
	Rules  []AutoMergeRule `json:"rules,omitempty"`
}

AutoMerge are a cluster's auto-merge rules.

type AutoMergeRule added in v0.29.0

type AutoMergeRule struct {
	Name       string              `json:"name"`
	Users      []string            `json:"users,omitempty"`
	Groups     []string            `json:"groups,omitempty"`
	Templates  []string            `json:"templates,omitempty"`
	Parameters map[string][]string `json:"parameters,omitempty"`
	// Actions: order, teardown; empty = order only.
	Actions []string `json:"actions,omitempty"`
}

AutoMergeRule allows auto-merge for some orderers, templates and parameter values.

func (AutoMergeRule) String added in v0.29.0

func (r AutoMergeRule) String() string

String is the rule in one line, e.g. "persona-test-vms: group:default/ai-personas; templates vm; size=small".

type Client

type Client struct {
	BaseURL    string
	HTTPClient *http.Client
}

Client talks to one machinery-order-service.

func New

func New(baseURL string, httpClient *http.Client) *Client

New returns a client for baseURL using httpClient (which carries the auth).

func (*Client) Cancel

func (c *Client) Cancel(id string) (*Order, error)

Cancel asks to withdraw an order (before its merge).

func (*Client) Clusters

func (c *Client) Clusters() ([]Cluster, error)

Clusters lists the management clusters.

func (*Client) Create

func (c *Client) Create(req CreateRequest) (*Order, error)

Create places an order.

func (*Client) Get

func (c *Client) Get(id string) (*Order, error)

Get reads one order.

func (*Client) List

func (c *Client) List(opt ListOptions) ([]*Order, error)

List returns the orders the caller may see, newest first.

func (*Client) Teardown added in v0.30.0

func (c *Client) Teardown(id string, req TeardownRequest) (*Order, error)

Teardown asks to remove what a merged order built: the service opens a delete-claim pull request (machinery-order-service ADR 0003).

type Cluster

type Cluster struct {
	Name       string `json:"name"`
	Lab        string `json:"lab,omitempty"`
	Cordoned   bool   `json:"cordoned"`
	Repository string `json:"repository,omitempty"`
	OrdersPath string `json:"ordersPath,omitempty"`
	// AutoMerge says who may order with --auto-merge on this cluster.
	AutoMerge *AutoMerge `json:"autoMerge,omitempty"`
}

Cluster is a management cluster orders can go to.

type CreateRequest

type CreateRequest struct {
	Template          string         `json:"template"`
	Parameters        map[string]any `json:"parameters,omitempty"`
	ManagementCluster string         `json:"managementCluster"`
	Reason            string         `json:"reason,omitempty"`
	// AutoMerge asks the service to merge the pull request once its checks
	// pass; the service refuses (403) unless a rule of the cluster allows it.
	AutoMerge bool `json:"autoMerge,omitempty"`
}

CreateRequest is the body of POST /api/v1/orders.

type ListOptions

type ListOptions struct {
	Mine    bool
	Phase   string
	Cluster string
}

ListOptions narrow a list.

type Order

type Order struct {
	Metadata struct {
		Name              string    `json:"name"`
		CreationTimestamp time.Time `json:"creationTimestamp"`
		ResourceVersion   string    `json:"resourceVersion,omitempty"`
	} `json:"metadata"`
	Spec struct {
		Template    string `json:"template"`
		RequestedBy string `json:"requestedBy,omitempty"`
		Reason      string `json:"reason,omitempty"`
		Placement   struct {
			ManagementCluster string `json:"managementCluster"`
		} `json:"placement"`
		Cancel    bool `json:"cancel,omitempty"`
		AutoMerge *struct {
			Rule string `json:"rule"`
		} `json:"autoMerge,omitempty"`
		Teardown *struct {
			Attempt     int    `json:"attempt"`
			RequestedBy string `json:"requestedBy,omitempty"`
			Reason      string `json:"reason,omitempty"`
			AutoMerge   *struct {
				Rule string `json:"rule"`
			} `json:"autoMerge,omitempty"`
		} `json:"teardown,omitempty"`
	} `json:"spec"`
	Status struct {
		Phase    string `json:"phase,omitempty"`
		Message  string `json:"message,omitempty"`
		Delivery *struct {
			PullRequest *struct {
				Number int    `json:"number"`
				URL    string `json:"url"`
				State  string `json:"state"`
			} `json:"pullRequest,omitempty"`
		} `json:"delivery,omitempty"`
		Teardown *struct {
			Attempt  int    `json:"attempt"`
			Outcome  string `json:"outcome,omitempty"`
			Delivery *struct {
				PullRequest *struct {
					Number int    `json:"number"`
					URL    string `json:"url"`
					State  string `json:"state"`
				} `json:"pullRequest,omitempty"`
			} `json:"delivery,omitempty"`
		} `json:"teardown,omitempty"`
		Live *struct {
			Found         bool   `json:"found"`
			Ready         bool   `json:"ready"`
			StatusMessage string `json:"statusMessage,omitempty"`
			Address       string `json:"address,omitempty"`
		} `json:"live,omitempty"`
		History []struct {
			Phase   string    `json:"phase"`
			Time    time.Time `json:"time"`
			Message string    `json:"message,omitempty"`
		} `json:"history,omitempty"`
		Conditions []struct {
			Type    string `json:"type"`
			Status  string `json:"status"`
			Reason  string `json:"reason,omitempty"`
			Message string `json:"message,omitempty"`
		} `json:"conditions,omitempty"`
	} `json:"status"`

	Raw json.RawMessage `json:"-"`
}

Order is the part of an Order claims shows; Raw is the full object as the service sent it (for -o json).

func (*Order) Address

func (o *Order) Address() string

Address is what machinery reports for the live resource (a VM's IP).

func (*Order) ID

func (o *Order) ID() string

ID is the order ID.

func (*Order) PRURL

func (o *Order) PRURL() string

PRURL is the pull request's URL, "" before there is one.

func (*Order) Phase

func (o *Order) Phase() string

Phase is the phase, "Pending" while the service has not set one yet.

func (*Order) TeardownOutcome added in v0.30.0

func (o *Order) TeardownOutcome() string

TeardownOutcome is the outcome of the current teardown request: "" while it runs or when none was asked for, else Withdrawn, Failed or Deleted.

func (*Order) TeardownPRURL added in v0.30.0

func (o *Order) TeardownPRURL() string

TeardownPRURL is the teardown pull request's URL, "" before there is one.

func (*Order) TearingDown added in v0.30.0

func (o *Order) TearingDown() bool

TearingDown reports whether a teardown was asked for and has no outcome yet, so Ready is not where the order stops.

type TeardownRequest added in v0.30.0

type TeardownRequest struct {
	Reason    string `json:"reason,omitempty"`
	AutoMerge bool   `json:"autoMerge,omitempty"`
}

TeardownRequest is the body of POST /api/v1/orders/{id}/teardown.

Jump to

Keyboard shortcuts

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