From 4beea0f215501433c02d03d206891f0392c0f1f0 Mon Sep 17 00:00:00 2001 From: Lukasz Zajaczkowski Date: Mon, 3 Jun 2024 10:47:56 +0200 Subject: [PATCH] add CustomStackRun --- client.go | 335 ++++++++++++++++++++++++++++++++++++++ graph/stack.graphql | 12 ++ graph/stack_model.graphql | 34 ++++ models_gen.go | 30 ++++ schema/schema.graphql | 38 +++++ 5 files changed, 449 insertions(+) diff --git a/client.go b/client.go index 4cafc47..98abac4 100644 --- a/client.go +++ b/client.go @@ -129,6 +129,8 @@ type ConsoleClient interface { CompletesStackRun(ctx context.Context, id string, attributes StackRunAttributes, interceptors ...clientv2.RequestInterceptor) (*CompletesStackRun, error) AddStackRunLogs(ctx context.Context, id string, attributes RunLogAttributes, interceptors ...clientv2.RequestInterceptor) (*AddStackRunLogs, error) UpdateStackRunStep(ctx context.Context, id string, attributes RunStepAttributes, interceptors ...clientv2.RequestInterceptor) (*UpdateStackRunStep, error) + UpsertCustomStackRun(ctx context.Context, attributes CustomStackRunAttributes, interceptors ...clientv2.RequestInterceptor) (*UpsertCustomStackRun, error) + DeleteCustomStackRun(ctx context.Context, id string, interceptors ...clientv2.RequestInterceptor) (*DeleteCustomStackRun, error) CreateAccessToken(ctx context.Context, interceptors ...clientv2.RequestInterceptor) (*CreateAccessToken, error) DeleteAccessToken(ctx context.Context, token string, interceptors ...clientv2.RequestInterceptor) (*DeleteAccessToken, error) ListAccessTokens(ctx context.Context, cursor *string, before *string, last *int64, interceptors ...clientv2.RequestInterceptor) (*ListAccessTokens, error) @@ -3309,6 +3311,162 @@ func (t *StackHookFragment) GetAfterStage() *StepStage { return &t.AfterStage } +type CustomStackRunFragment struct { + ID string "json:\"id\" graphql:\"id\"" + Name string "json:\"name\" graphql:\"name\"" + Stack *CustomStackRunFragment_Stack "json:\"stack,omitempty\" graphql:\"stack\"" + Documentation *string "json:\"documentation,omitempty\" graphql:\"documentation\"" + Commands []*StackCommandFragment "json:\"commands,omitempty\" graphql:\"commands\"" + Configuration []*PrConfigurationFragment "json:\"configuration,omitempty\" graphql:\"configuration\"" +} + +func (t *CustomStackRunFragment) GetID() string { + if t == nil { + t = &CustomStackRunFragment{} + } + return t.ID +} +func (t *CustomStackRunFragment) GetName() string { + if t == nil { + t = &CustomStackRunFragment{} + } + return t.Name +} +func (t *CustomStackRunFragment) GetStack() *CustomStackRunFragment_Stack { + if t == nil { + t = &CustomStackRunFragment{} + } + return t.Stack +} +func (t *CustomStackRunFragment) GetDocumentation() *string { + if t == nil { + t = &CustomStackRunFragment{} + } + return t.Documentation +} +func (t *CustomStackRunFragment) GetCommands() []*StackCommandFragment { + if t == nil { + t = &CustomStackRunFragment{} + } + return t.Commands +} +func (t *CustomStackRunFragment) GetConfiguration() []*PrConfigurationFragment { + if t == nil { + t = &CustomStackRunFragment{} + } + return t.Configuration +} + +type StackCommandFragment struct { + Cmd string "json:\"cmd\" graphql:\"cmd\"" + Args []*string "json:\"args,omitempty\" graphql:\"args\"" + Dir *string "json:\"dir,omitempty\" graphql:\"dir\"" +} + +func (t *StackCommandFragment) GetCmd() string { + if t == nil { + t = &StackCommandFragment{} + } + return t.Cmd +} +func (t *StackCommandFragment) GetArgs() []*string { + if t == nil { + t = &StackCommandFragment{} + } + return t.Args +} +func (t *StackCommandFragment) GetDir() *string { + if t == nil { + t = &StackCommandFragment{} + } + return t.Dir +} + +type PrConfigurationFragment struct { + Type ConfigurationType "json:\"type\" graphql:\"type\"" + Name string "json:\"name\" graphql:\"name\"" + Default *string "json:\"default,omitempty\" graphql:\"default\"" + Documentation *string "json:\"documentation,omitempty\" graphql:\"documentation\"" + Longform *string "json:\"longform,omitempty\" graphql:\"longform\"" + Placeholder *string "json:\"placeholder,omitempty\" graphql:\"placeholder\"" + Optional *bool "json:\"optional,omitempty\" graphql:\"optional\"" + Condition *PrConfigurationConditionFragment "json:\"condition,omitempty\" graphql:\"condition\"" +} + +func (t *PrConfigurationFragment) GetType() *ConfigurationType { + if t == nil { + t = &PrConfigurationFragment{} + } + return &t.Type +} +func (t *PrConfigurationFragment) GetName() string { + if t == nil { + t = &PrConfigurationFragment{} + } + return t.Name +} +func (t *PrConfigurationFragment) GetDefault() *string { + if t == nil { + t = &PrConfigurationFragment{} + } + return t.Default +} +func (t *PrConfigurationFragment) GetDocumentation() *string { + if t == nil { + t = &PrConfigurationFragment{} + } + return t.Documentation +} +func (t *PrConfigurationFragment) GetLongform() *string { + if t == nil { + t = &PrConfigurationFragment{} + } + return t.Longform +} +func (t *PrConfigurationFragment) GetPlaceholder() *string { + if t == nil { + t = &PrConfigurationFragment{} + } + return t.Placeholder +} +func (t *PrConfigurationFragment) GetOptional() *bool { + if t == nil { + t = &PrConfigurationFragment{} + } + return t.Optional +} +func (t *PrConfigurationFragment) GetCondition() *PrConfigurationConditionFragment { + if t == nil { + t = &PrConfigurationFragment{} + } + return t.Condition +} + +type PrConfigurationConditionFragment struct { + Operation Operation "json:\"operation\" graphql:\"operation\"" + Field string "json:\"field\" graphql:\"field\"" + Value *string "json:\"value,omitempty\" graphql:\"value\"" +} + +func (t *PrConfigurationConditionFragment) GetOperation() *Operation { + if t == nil { + t = &PrConfigurationConditionFragment{} + } + return &t.Operation +} +func (t *PrConfigurationConditionFragment) GetField() string { + if t == nil { + t = &PrConfigurationConditionFragment{} + } + return t.Field +} +func (t *PrConfigurationConditionFragment) GetValue() *string { + if t == nil { + t = &PrConfigurationConditionFragment{} + } + return t.Value +} + type PipelineGateEdgeFragment_Node_PipelineGateFragment_Spec_GateSpecFragment_Job_JobSpecFragment_Containers_ContainerSpecFragment_Env struct { Name string "json:\"name\" graphql:\"name\"" Value string "json:\"value\" graphql:\"value\"" @@ -4960,6 +5118,17 @@ func (t *StackRunBaseFragment_JobSpec_JobSpecFragment_Containers_ContainerSpecFr return t.Secret } +type CustomStackRunFragment_Stack struct { + ID *string "json:\"id,omitempty\" graphql:\"id\"" +} + +func (t *CustomStackRunFragment_Stack) GetID() *string { + if t == nil { + t = &CustomStackRunFragment_Stack{} + } + return t.ID +} + type CreateClusterBackup_CreateClusterBackup_ClusterBackupFragment_Cluster struct { ID string "json:\"id\" graphql:\"id\"" } @@ -10300,6 +10469,28 @@ func (t *AddStackRunLogs_AddRunLogs) GetUpdatedAt() *string { return t.UpdatedAt } +type UpsertCustomStackRun_UpsertCustomStackRun_CustomStackRunFragment_Stack struct { + ID *string "json:\"id,omitempty\" graphql:\"id\"" +} + +func (t *UpsertCustomStackRun_UpsertCustomStackRun_CustomStackRunFragment_Stack) GetID() *string { + if t == nil { + t = &UpsertCustomStackRun_UpsertCustomStackRun_CustomStackRunFragment_Stack{} + } + return t.ID +} + +type DeleteCustomStackRun_DeleteCustomStackRun_CustomStackRunFragment_Stack struct { + ID *string "json:\"id,omitempty\" graphql:\"id\"" +} + +func (t *DeleteCustomStackRun_DeleteCustomStackRun_CustomStackRunFragment_Stack) GetID() *string { + if t == nil { + t = &DeleteCustomStackRun_DeleteCustomStackRun_CustomStackRunFragment_Stack{} + } + return t.ID +} + type ListAccessTokens_AccessTokens struct { Edges []*AccessTokenEdgeFragment "json:\"edges,omitempty\" graphql:\"edges\"" } @@ -11739,6 +11930,28 @@ func (t *UpdateStackRunStep) GetUpdateRunStep() *RunStepFragment { return t.UpdateRunStep } +type UpsertCustomStackRun struct { + UpsertCustomStackRun *CustomStackRunFragment "json:\"upsertCustomStackRun,omitempty\" graphql:\"upsertCustomStackRun\"" +} + +func (t *UpsertCustomStackRun) GetUpsertCustomStackRun() *CustomStackRunFragment { + if t == nil { + t = &UpsertCustomStackRun{} + } + return t.UpsertCustomStackRun +} + +type DeleteCustomStackRun struct { + DeleteCustomStackRun *CustomStackRunFragment "json:\"deleteCustomStackRun,omitempty\" graphql:\"deleteCustomStackRun\"" +} + +func (t *DeleteCustomStackRun) GetDeleteCustomStackRun() *CustomStackRunFragment { + if t == nil { + t = &DeleteCustomStackRun{} + } + return t.DeleteCustomStackRun +} + type CreateAccessToken struct { CreateAccessToken *AccessTokenFragment "json:\"createAccessToken,omitempty\" graphql:\"createAccessToken\"" } @@ -22226,6 +22439,126 @@ func (c *Client) UpdateStackRunStep(ctx context.Context, id string, attributes R return &res, nil } +const UpsertCustomStackRunDocument = `mutation UpsertCustomStackRun ($attributes: CustomStackRunAttributes!) { + upsertCustomStackRun(attributes: $attributes) { + ... CustomStackRunFragment + } +} +fragment CustomStackRunFragment on CustomStackRun { + id + name + stack { + id + } + documentation + commands { + ... StackCommandFragment + } + configuration { + ... PrConfigurationFragment + } +} +fragment StackCommandFragment on StackCommand { + cmd + args + dir +} +fragment PrConfigurationFragment on PrConfiguration { + type + name + default + documentation + longform + placeholder + optional + condition { + ... PrConfigurationConditionFragment + } +} +fragment PrConfigurationConditionFragment on PrConfigurationCondition { + operation + field + value +} +` + +func (c *Client) UpsertCustomStackRun(ctx context.Context, attributes CustomStackRunAttributes, interceptors ...clientv2.RequestInterceptor) (*UpsertCustomStackRun, error) { + vars := map[string]interface{}{ + "attributes": attributes, + } + + var res UpsertCustomStackRun + if err := c.Client.Post(ctx, "UpsertCustomStackRun", UpsertCustomStackRunDocument, &res, vars, interceptors...); err != nil { + if c.Client.ParseDataWhenErrors { + return &res, err + } + + return nil, err + } + + return &res, nil +} + +const DeleteCustomStackRunDocument = `mutation DeleteCustomStackRun ($id: ID!) { + deleteCustomStackRun(id: $id) { + ... CustomStackRunFragment + } +} +fragment CustomStackRunFragment on CustomStackRun { + id + name + stack { + id + } + documentation + commands { + ... StackCommandFragment + } + configuration { + ... PrConfigurationFragment + } +} +fragment StackCommandFragment on StackCommand { + cmd + args + dir +} +fragment PrConfigurationFragment on PrConfiguration { + type + name + default + documentation + longform + placeholder + optional + condition { + ... PrConfigurationConditionFragment + } +} +fragment PrConfigurationConditionFragment on PrConfigurationCondition { + operation + field + value +} +` + +func (c *Client) DeleteCustomStackRun(ctx context.Context, id string, interceptors ...clientv2.RequestInterceptor) (*DeleteCustomStackRun, error) { + vars := map[string]interface{}{ + "id": id, + } + + var res DeleteCustomStackRun + if err := c.Client.Post(ctx, "DeleteCustomStackRun", DeleteCustomStackRunDocument, &res, vars, interceptors...); err != nil { + if c.Client.ParseDataWhenErrors { + return &res, err + } + + return nil, err + } + + return &res, nil +} + const CreateAccessTokenDocument = `mutation CreateAccessToken { createAccessToken { ... AccessTokenFragment @@ -22628,6 +22961,8 @@ var DocumentOperationNames = map[string]string{ CompletesStackRunDocument: "CompletesStackRun", AddStackRunLogsDocument: "AddStackRunLogs", UpdateStackRunStepDocument: "UpdateStackRunStep", + UpsertCustomStackRunDocument: "UpsertCustomStackRun", + DeleteCustomStackRunDocument: "DeleteCustomStackRun", CreateAccessTokenDocument: "CreateAccessToken", DeleteAccessTokenDocument: "DeleteAccessToken", ListAccessTokensDocument: "ListAccessTokens", diff --git a/graph/stack.graphql b/graph/stack.graphql index 58ea110..3df3f3d 100644 --- a/graph/stack.graphql +++ b/graph/stack.graphql @@ -87,3 +87,15 @@ mutation UpdateStackRunStep($id: ID!, $attributes: RunStepAttributes!) { ...RunStepFragment } } + +mutation UpsertCustomStackRun($attributes: CustomStackRunAttributes!) { + upsertCustomStackRun(attributes: $attributes) { + ...CustomStackRunFragment + } +} + +mutation DeleteCustomStackRun($id: ID!) { + deleteCustomStackRun(id: $id) { + ...CustomStackRunFragment + } +} \ No newline at end of file diff --git a/graph/stack_model.graphql b/graph/stack_model.graphql index 3af98a2..85bfd17 100644 --- a/graph/stack_model.graphql +++ b/graph/stack_model.graphql @@ -130,3 +130,37 @@ fragment StackHookFragment on StackHook { args afterStage } + +fragment CustomStackRunFragment on CustomStackRun { + id + name + stack { + id + } + documentation + commands { ...StackCommandFragment} + configuration { ...PrConfigurationFragment} +} + +fragment StackCommandFragment on StackCommand { + cmd + args + dir +} + +fragment PrConfigurationFragment on PrConfiguration { + type + name + default + documentation + longform + placeholder + optional + condition { ...PrConfigurationConditionFragment} +} + +fragment PrConfigurationConditionFragment on PrConfigurationCondition { + operation + field + value +} \ No newline at end of file diff --git a/models_gen.go b/models_gen.go index da2e844..99e0058 100644 --- a/models_gen.go +++ b/models_gen.go @@ -1210,6 +1210,8 @@ type DeploymentSettings struct { PrometheusConnection *HTTPConnection `json:"prometheusConnection,omitempty"` // custom helm values to apply to all agents (useful for things like adding customary annotations/labels) AgentHelmValues *string `json:"agentHelmValues,omitempty"` + // global settings for stack configuration + Stacks *StackSettings `json:"stacks,omitempty"` // The console's expected agent version AgentVsn string `json:"agentVsn"` // the latest known k8s version @@ -1237,6 +1239,8 @@ type DeploymentSettingsAttributes struct { DeployerRepositoryID *string `json:"deployerRepositoryId,omitempty"` // custom helm values to apply to all agents (useful for things like adding customary annotations/labels) AgentHelmValues *string `json:"agentHelmValues,omitempty"` + // global configuration for stack execution + Stacks *StackSettingsAttributes `json:"stacks,omitempty"` // connection details for a prometheus instance to use PrometheusConnection *HTTPConnectionAttributes `json:"prometheusConnection,omitempty"` // connection details for a loki instance to use @@ -3768,6 +3772,8 @@ type ServiceDeployment struct { Contexts []*ServiceContext `json:"contexts,omitempty"` // the dependencies of this service, actualization will not happen until all are HEALTHY Dependencies []*ServiceDependency `json:"dependencies,omitempty"` + // imports from stack outputs + Imports []*ServiceImport `json:"imports,omitempty"` // a relay connection of all revisions of this service, these are periodically pruned up to a history limit Revisions *RevisionConnection `json:"revisions,omitempty"` // whether this service is editable @@ -3796,6 +3802,7 @@ type ServiceDeploymentAttributes struct { ReadBindings []*PolicyBindingAttributes `json:"readBindings,omitempty"` WriteBindings []*PolicyBindingAttributes `json:"writeBindings,omitempty"` ContextBindings []*ContextBindingAttributes `json:"contextBindings,omitempty"` + Imports []*ServiceImportAttributes `json:"imports,omitempty"` } type ServiceDeploymentConnection struct { @@ -3819,6 +3826,21 @@ type ServiceErrorAttributes struct { Message string `json:"message"` } +// Import of stack data into a service's context +type ServiceImport struct { + ID string `json:"id"` + // The stack you're importing from + Stack *InfrastructureStack `json:"stack,omitempty"` + // The outputs of that stack + Outputs []*StackOutput `json:"outputs,omitempty"` + InsertedAt *string `json:"insertedAt,omitempty"` + UpdatedAt *string `json:"updatedAt,omitempty"` +} + +type ServiceImportAttributes struct { + StackID string `json:"stackId"` +} + type ServicePort struct { Name *string `json:"name,omitempty"` Protocol *string `json:"protocol,omitempty"` @@ -4140,6 +4162,14 @@ type StackRunEdge struct { Cursor *string `json:"cursor,omitempty"` } +type StackSettings struct { + JobSpec *JobGateSpec `json:"jobSpec,omitempty"` +} + +type StackSettingsAttributes struct { + JobSpec *GateJobAttributes `json:"jobSpec,omitempty"` +} + type StackState struct { ID string `json:"id"` Plan *string `json:"plan,omitempty"` diff --git a/schema/schema.graphql b/schema/schema.graphql index bcf0aec..ab429bd 100644 --- a/schema/schema.graphql +++ b/schema/schema.graphql @@ -805,6 +805,9 @@ type DeploymentSettings { "custom helm values to apply to all agents (useful for things like adding customary annotations\/labels)" agentHelmValues: String + "global settings for stack configuration" + stacks: StackSettings + "The console's expected agent version" agentVsn: String! @@ -837,6 +840,10 @@ type DeploymentSettings { updatedAt: DateTime } +type StackSettings { + jobSpec: JobGateSpec +} + "the details of how to connect to a http service like prometheus" type HttpConnection { host: String! @@ -856,6 +863,9 @@ input DeploymentSettingsAttributes { "custom helm values to apply to all agents (useful for things like adding customary annotations\/labels)" agentHelmValues: String + "global configuration for stack execution" + stacks: StackSettingsAttributes + "connection details for a prometheus instance to use" prometheusConnection: HttpConnectionAttributes @@ -886,6 +896,10 @@ input RbacAttributes { writeBindings: [PolicyBindingAttributes] } +input StackSettingsAttributes { + jobSpec: GateJobAttributes +} + enum ObservabilityProviderType { DATADOG NEWRELIC @@ -2538,6 +2552,12 @@ input ServiceDeploymentAttributes { writeBindings: [PolicyBindingAttributes] contextBindings: [ContextBindingAttributes] + + imports: [ServiceImportAttributes] +} + +input ServiceImportAttributes { + stackId: ID! } input SyncConfigAttributes { @@ -2777,6 +2797,9 @@ type ServiceDeployment { "the dependencies of this service, actualization will not happen until all are HEALTHY" dependencies: [ServiceDependency] + "imports from stack outputs" + imports: [ServiceImport] + "a relay connection of all revisions of this service, these are periodically pruned up to a history limit" revisions(after: String, first: Int, before: String, last: Int): RevisionConnection @@ -3000,6 +3023,21 @@ type ServiceDependency { updatedAt: DateTime } +"Import of stack data into a service's context" +type ServiceImport { + id: ID! + + "The stack you're importing from" + stack: InfrastructureStack + + "The outputs of that stack" + outputs: [StackOutput] + + insertedAt: DateTime + + updatedAt: DateTime +} + "A tree view of the kubernetes object hierarchy beneath a component" type ComponentTree { root: KubernetesUnstructured