fix: 解耦 runner 与 placement 实现
This commit is contained in:
@@ -13,13 +13,12 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
EnvAssignmentID = "CI_ASSIGNMENT_ID"
|
||||
EnvCapability = "CI_RUNNER_CAPABILITY"
|
||||
EnvFacadeURL = "CI_RUNNER_FACADE_URL"
|
||||
EnvFacadeID = "CI_RUNNER_FACADE_SPIFFE_ID"
|
||||
EnvSPIFFEID = "CI_SPIFFE_ID"
|
||||
EnvWorkloadClass = "CI_WORKLOAD_CLASS"
|
||||
EnvDriver = "CI_WORKLOAD_DRIVER"
|
||||
EnvAssignmentID = "CI_ASSIGNMENT_ID"
|
||||
EnvCapability = "CI_RUNNER_CAPABILITY"
|
||||
EnvFacadeURL = "CI_RUNNER_FACADE_URL"
|
||||
EnvFacadeID = "CI_RUNNER_FACADE_SPIFFE_ID"
|
||||
EnvSPIFFEID = "CI_SPIFFE_ID"
|
||||
EnvRunnerLabels = "CI_RUNNER_LABELS_JSON"
|
||||
)
|
||||
|
||||
// Bootstrap emits assignment-scoped launch configuration. FacadeURL is the
|
||||
@@ -43,14 +42,17 @@ func (b Bootstrap) Environment(assignment taskassignment.Assignment) (map[string
|
||||
if capability == "" {
|
||||
return nil, errors.New("runner capability issuer is not configured")
|
||||
}
|
||||
labels, err := json.Marshal([]string{"self-hosted", string(assignment.Placement.Class), string(assignment.Placement.Driver)})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("encode runner labels: %w", err)
|
||||
}
|
||||
return map[string]string{
|
||||
EnvAssignmentID: assignment.ID,
|
||||
EnvCapability: capability,
|
||||
EnvFacadeURL: b.FacadeURL,
|
||||
EnvFacadeID: b.FacadeSPIFFEID,
|
||||
EnvSPIFFEID: assignment.Identity.SPIFFEID,
|
||||
EnvWorkloadClass: string(assignment.Placement.Class),
|
||||
EnvDriver: string(assignment.Placement.Driver),
|
||||
EnvRunnerLabels: string(labels),
|
||||
"SPIFFE_ENDPOINT_SOCKET": b.WorkloadAPIAddr,
|
||||
}, nil
|
||||
}
|
||||
@@ -69,7 +71,7 @@ type Registration struct {
|
||||
Ephemeral bool `json:"ephemeral"`
|
||||
}
|
||||
|
||||
func RegistrationJSON(assignmentID, capability, localProxyURL string, placement taskassignment.Placement) ([]byte, error) {
|
||||
func RegistrationJSON(assignmentID, capability, localProxyURL string, labels []string) ([]byte, error) {
|
||||
if assignmentID == "" || capability == "" {
|
||||
return nil, errors.New("assignment ID and runner capability are required")
|
||||
}
|
||||
@@ -77,13 +79,18 @@ func RegistrationJSON(assignmentID, capability, localProxyURL string, placement
|
||||
if err != nil || parsed.Scheme != "http" || parsed.Host == "" {
|
||||
return nil, errors.New("local runner proxy URL must be an absolute http URL")
|
||||
}
|
||||
if err := placement.Validate(); err != nil {
|
||||
return nil, err
|
||||
if len(labels) == 0 {
|
||||
return nil, errors.New("runner labels are required")
|
||||
}
|
||||
for _, label := range labels {
|
||||
if label == "" {
|
||||
return nil, errors.New("runner labels must not be empty")
|
||||
}
|
||||
}
|
||||
registration := Registration{
|
||||
Warning: "Generated for one preassigned task by gitea-dynamic-runner.",
|
||||
UUID: assignmentID, Name: assignmentID, Token: capability,
|
||||
Address: localProxyURL, Labels: []string{"self-hosted", string(placement.Class), string(placement.Driver)}, Ephemeral: true,
|
||||
Address: localProxyURL, Labels: append([]string(nil), labels...), Ephemeral: true,
|
||||
}
|
||||
data, err := json.MarshalIndent(registration, "", " ")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user