Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: connection from scraper #1589

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ coverprofile.out
junit-report.xml
nohup.out
.envrc
.creds
11 changes: 3 additions & 8 deletions api/v1/playbook_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/flanksource/commons/duration"
"github.com/flanksource/commons/utils"
"github.com/flanksource/duty/connection"
"github.com/flanksource/duty/models"
"github.com/flanksource/duty/types"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -237,8 +238,8 @@ func (git GitCheckout) GetCertificate() types.EnvVar {
type ExecAction struct {
// Script can be an inline script or a path to a script that needs to be executed
// On windows executed via powershell and in darwin and linux executed using bash
Script string `yaml:"script" json:"script" template:"true"`
Connections ExecConnections `yaml:"connections,omitempty" json:"connections,omitempty"`
Script string `yaml:"script" json:"script" template:"true"`
Connections connection.ExecConnections `yaml:"connections,omitempty" json:"connections,omitempty" template:"true"`
// Artifacts to save
Artifacts []Artifact `yaml:"artifacts,omitempty" json:"artifacts,omitempty" template:"true"`
// EnvVars are the environment variables that are accessible to exec processes
Expand All @@ -247,12 +248,6 @@ type ExecAction struct {
Checkout *GitCheckout `yaml:"checkout,omitempty" json:"checkout,omitempty"`
}

type ExecConnections struct {
AWS *AWSConnection `yaml:"aws,omitempty" json:"aws,omitempty"`
GCP *GCPConnection `yaml:"gcp,omitempty" json:"gcp,omitempty"`
Azure *AzureConnection `yaml:"azure,omitempty" json:"azure,omitempty"`
}

type connectionContext interface {
gocontext.Context
HydrateConnectionByURL(connectionName string) (*models.Connection, error)
Expand Down
30 changes: 0 additions & 30 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 57 additions & 8 deletions config/crds/mission-control.flanksource.com_playbooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -341,17 +341,15 @@ spec:
type: string
type: object
type: object
assumeRole:
type: string
connection:
description: ConnectionName of the connection. It'll
be used to populate the endpoint, accessKey and
secretKey.
type: string
endpoint:
type: string
objectPath:
description: glob path to restrict matches to a
subset
type: string
region:
type: string
secretKey:
Expand Down Expand Up @@ -448,10 +446,6 @@ spec:
description: Skip TLS verify when connecting to
aws
type: boolean
usePathStyle:
description: 'Use path style path: http://s3.amazonaws.com/BUCKET/KEY
instead of http://BUCKET.s3.amazonaws.com/KEY'
type: boolean
type: object
azure:
properties:
Expand Down Expand Up @@ -550,6 +544,8 @@ spec:
tenantID:
type: string
type: object
fromConfigItem:
type: string
gcp:
properties:
connection:
Expand Down Expand Up @@ -603,6 +599,59 @@ spec:
type: object
endpoint:
type: string
skipTLSVerify:
description: Skip TLS verify
type: boolean
type: object
kubernetes:
properties:
connection:
type: string
kubeconfig:
properties:
name:
type: string
value:
type: string
valueFrom:
properties:
configMapKeyRef:
properties:
key:
type: string
name:
type: string
required:
- key
type: object
helmRef:
properties:
key:
description: Key is a JSONPath expression
used to fetch the key from the merged
JSON.
type: string
name:
type: string
required:
- key
type: object
secretKeyRef:
properties:
key:
type: string
name:
type: string
required:
- key
type: object
serviceAccount:
description: ServiceAccount specifies the
service account whose token should be
fetched
type: string
type: object
type: object
type: object
type: object
env:
Expand Down
30 changes: 24 additions & 6 deletions config/schemas/playbook-spec.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"sessionToken": {
"$ref": "#/$defs/EnvVar"
},
"assumeRole": {
"type": "string"
},
"region": {
"type": "string"
},
Expand All @@ -25,12 +28,6 @@
},
"skipTLSVerify": {
"type": "boolean"
},
"objectPath": {
"type": "string"
},
"usePathStyle": {
"type": "boolean"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -203,6 +200,12 @@
},
"ExecConnections": {
"properties": {
"fromConfigItem": {
"type": "string"
},
"kubernetes": {
"$ref": "#/$defs/KubernetesConnection"
},
"aws": {
"$ref": "#/$defs/AWSConnection"
},
Expand All @@ -226,6 +229,9 @@
},
"credentials": {
"$ref": "#/$defs/EnvVar"
},
"skipTLSVerify": {
"type": "boolean"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -498,6 +504,18 @@
},
"type": "array"
},
"KubernetesConnection": {
"properties": {
"connection": {
"type": "string"
},
"kubeconfig": {
"$ref": "#/$defs/EnvVar"
}
},
"additionalProperties": false,
"type": "object"
},
"NotificationAction": {
"properties": {
"url": {
Expand Down
30 changes: 24 additions & 6 deletions config/schemas/playbook.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"sessionToken": {
"$ref": "#/$defs/EnvVar"
},
"assumeRole": {
"type": "string"
},
"region": {
"type": "string"
},
Expand All @@ -25,12 +28,6 @@
},
"skipTLSVerify": {
"type": "boolean"
},
"objectPath": {
"type": "string"
},
"usePathStyle": {
"type": "boolean"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -203,6 +200,12 @@
},
"ExecConnections": {
"properties": {
"fromConfigItem": {
"type": "string"
},
"kubernetes": {
"$ref": "#/$defs/KubernetesConnection"
},
"aws": {
"$ref": "#/$defs/AWSConnection"
},
Expand Down Expand Up @@ -231,6 +234,9 @@
},
"credentials": {
"$ref": "#/$defs/EnvVar"
},
"skipTLSVerify": {
"type": "boolean"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -503,6 +509,18 @@
},
"type": "array"
},
"KubernetesConnection": {
"properties": {
"connection": {
"type": "string"
},
"kubeconfig": {
"$ref": "#/$defs/EnvVar"
}
},
"additionalProperties": false,
"type": "object"
},
"ManagedFieldsEntry": {
"properties": {
"manager": {
Expand Down
18 changes: 18 additions & 0 deletions fixtures/playbooks/connection-from-scraper.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
apiVersion: mission-control.flanksource.com/v1
kind: Playbook
metadata:
name: kubernetes-connection-from-scraper
namespace: mc
spec:
configs:
- types:
- Kubernetes::Deployment
actions:
- exec:
script: "kubectl get deployments"
connections:
fromConfigItem: "{{.config.id}}"
name: list
category: Echoer
description: Lists all deployments
Loading
Loading