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: generate plan yamls #2177

Merged
merged 85 commits into from Mar 13, 2024
Merged

feat: generate plan yamls #2177

merged 85 commits into from Mar 13, 2024

Conversation

tedim52
Copy link
Contributor

@tedim52 tedim52 commented Feb 17, 2024

Description:

This change implements the generation of a yaml that represents the effect of a sequence of instructions on an enclave. The major changes are as follows:

  • Adds gRPC endpoints GetStarlarkPackge/ScriptPlanYaml to APIC and Enclave Manager for returning this yaml
  • Implements PlanYaml object and yaml generation logic in startosis_engine
  • Adds UpdatePlan(plan *PlanYaml) method to KurtosisInstruction interface so each instruction implements logic for updating the plan yaml
    • Most of the knowledge needed to generate the yaml comes from the interpretation phase and is simply passed into yaml generation logic

Tests are in startosis_interpreter_plan_yaml_tests.go and demonstrate how the InstructionsPlan generates the yaml via the PlanYaml object.

eg. starlark script turned plan yaml:

def run(plan, hi_files_artifact):
	service = plan.add_service(
		name="db",
		config=ServiceConfig(
			image="postgres:latest",
			env_vars={
				"POSTGRES_DB": "kurtosis",
				"POSTGRES_USER": "kurtosis",
				"POSTGRES_PASSWORD": "kurtosis",
			},
			files = {
				"/root": hi_files_artifact,
			}
		)
	)
	execResult = plan.exec(
		service_name="db",
		recipe=ExecRecipe(
			command=["echo", service.ip_address + " " + service.hostname]
		),
		acceptable_codes=[0],
	)	
	runShResult = plan.run_sh(
		run="echo " + execResult["code"] + " " + execResult["output"],
	)
	plan.run_sh(
		run="echo " + runShResult.code + " " + runShResult.output,
	)

plan yaml:

packageId: DEFAULT_PACKAGE_ID_FOR_SCRIPT
services:
- uuid: "1"
  name: db
  image:
    name: postgres:latest
  envVars:
  - key: POSTGRES_DB
    value: kurtosis
  - key: POSTGRES_PASSWORD
    value: kurtosis
  - key: POSTGRES_USER
    value: kurtosis
  files:
  - mountPath: /root
    filesArtifacts:
    - uuid: "2"
      name: hi-file
filesArtifacts:
- uuid: "2"
  name: hi-file
tasks:
- uuid: "3"
  taskType: exec
  command:
  - echo
  - '{{ kurtosis.1.ip_address }} {{ kurtosis.1.hostname }}'
  serviceName: db
  acceptableCodes:
  - 0
- uuid: "4"
  taskType: sh
  command:
  - echo {{ kurtosis.3.code }} {{ kurtosis.3.output }}
  image: badouralix/curl-jq
- uuid: "5"
  taskType: sh
  command:
  - echo {{ kurtosis.4.code }} {{ kurtosis.4.output }}
  image: badouralix/curl-jq

Is this change user facing?

NO

References:

The Enclave Manager uses this plan yaml to render packages in the Enclave Builder:
#2250

Copy link

gitguardian bot commented Feb 17, 2024

⚠️ GitGuardian has uncovered 39 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
9966505 Triggered Generic Password ec3cf48 core/server/api_container/server/startosis_engine/startosis_interpreter_plan_yaml_test.go View secret
9966505 Triggered Generic Password ec3cf48 core/server/api_container/server/startosis_engine/startosis_interpreter_plan_yaml_test.go View secret
9966505 Triggered Generic Password f69701f core/server/api_container/server/startosis_engine/startosis_interpreter_plan_yaml_test.go View secret
9966505 Triggered Generic Password b254a49 core/server/api_container/server/startosis_engine/startosis_interpreter_plan_yaml_test.go View secret
9966505 Triggered Generic Password b254a49 core/server/api_container/server/startosis_engine/startosis_interpreter_plan_yaml_test.go View secret
9583343 Triggered Generic Password 3998b57 core/server/api_container/server/startosis_engine/plan.yml View secret
9583343 Triggered Generic Password 8c7a419 core/server/api_container/server/startosis_engine/plan_yaml_generator_test.go View secret
9583343 Triggered Generic Password 323ac97 core/server/api_container/server/startosis_engine/plan_yaml_generator_test.go View secret
9583343 Triggered Generic Password 80ace33 core/server/api_container/server/startosis_engine/plan.yml View secret
9583343 Triggered Generic Password 908ad7d core/server/api_container/server/startosis_engine/plan_yaml_generator_test.go View secret
9583343 Triggered Generic Password ccc256b core/server/api_container/server/startosis_engine/plan.yml View secret
9583343 Triggered Generic Password 458fd75 core/server/api_container/server/startosis_engine/plan_yaml_generator_test.go View secret
9583343 Triggered Generic Password ccc256b core/server/api_container/server/startosis_engine/plan_yaml_generator_test.go View secret
9583343 Triggered Generic Password 21e4ead core/server/api_container/server/startosis_engine/plan.yml View secret
9583343 Triggered Generic Password 13a5cba core/server/api_container/server/startosis_engine/plan_yaml_generator_test.go View secret
9583343 Triggered Generic Password 0544d1b core/server/api_container/server/startosis_engine/plan.yml View secret
9583343 Triggered Generic Password 3998b57 core/server/api_container/server/startosis_engine/plan.yml View secret
9583343 Triggered Generic Password 9109cac core/server/api_container/server/startosis_engine/plan_yaml_generator_test.go View secret
9583343 Triggered Generic Password 21e4ead core/server/api_container/server/startosis_engine/plan.yml View secret
9583343 Triggered Generic Password 8c7a419 core/server/api_container/server/startosis_engine/plan_yaml_generator_test.go View secret
9583343 Triggered Generic Password 13a5cba core/server/api_container/server/startosis_engine/plan_yaml_generator_test.go View secret
9583343 Triggered Generic Password 679ed73 core/server/api_container/server/startosis_engine/plan_yaml_generator_test.go View secret
9583343 Triggered Generic Password d190067 core/server/api_container/server/startosis_engine/plan.yml View secret
9583343 Triggered Generic Password a4e7031 core/server/api_container/server/startosis_engine/plan_yaml_generator_test.go View secret
9583343 Triggered Generic Password 13a5cba core/server/api_container/server/startosis_engine/plan.yml View secret
9583343 Triggered Generic Password aef291e core/server/api_container/server/startosis_engine/plan.yml View secret
9583343 Triggered Generic Password 13a5cba core/server/api_container/server/startosis_engine/plan_yaml_generator_test.go View secret
9583343 Triggered Generic Password aef291e core/server/api_container/server/startosis_engine/plan_yaml_generator_test.go View secret
9583343 Triggered Generic Password ae9f7ce core/server/api_container/server/startosis_engine/plan_yaml_generator_test.go View secret
9583343 Triggered Generic Password 80ace33 core/server/api_container/server/startosis_engine/plan.yml View secret
9583343 Triggered Generic Password 21e4ead core/server/api_container/server/startosis_engine/plan_yaml_generator_test.go View secret
9583343 Triggered Generic Password a4e7031 core/server/api_container/server/startosis_engine/plan_yaml_generator_test.go View secret
9583343 Triggered Generic Password 9109cac core/server/api_container/server/startosis_engine/plan_yaml_generator_test.go View secret
9583343 Triggered Generic Password 21e4ead core/server/api_container/server/startosis_engine/plan_yaml_generator_test.go View secret
9583343 Triggered Generic Password 13a5cba core/server/api_container/server/startosis_engine/plan.yml View secret
9583343 Triggered Generic Password 323ac97 core/server/api_container/server/startosis_engine/plan.yml View secret
9583343 Triggered Generic Password d190067 core/server/api_container/server/startosis_engine/plan.yml View secret
9583343 Triggered Generic Password 03a7535 core/server/api_container/server/startosis_engine/plan.yml View secret
9583343 Triggered Generic Password ec3cf48 core/server/api_container/server/startosis_engine/startosis_interpreter_plan_yaml_test.go View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Our GitHub checks need improvements? Share your feedbacks!

@tedim52 tedim52 marked this pull request as draft February 17, 2024 18:08
@tedim52 tedim52 changed the title feat: generate plan yamls from dry run feat: generate plan yamls Mar 11, 2024
@tedim52
Copy link
Contributor Author

tedim52 commented Mar 11, 2024

The GitGuardian secrets are only picking up the PASSWORD env vars that I set when writing tests, no secrets were actually used in this PR.

@tedim52
Copy link
Contributor Author

tedim52 commented Mar 11, 2024

I considered renaming PlanYaml to EnclaveState for a while as the yaml represents state of an enclave post an instructions plan containing services and files artifacts, but the fact that tasks are in it throws me off a bit as tasks aren't really state, but maybe we consider them so. Open to suggestions on naming.

Copy link
Contributor

@h4ck3rk3y h4ck3rk3y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spent some time reviewing this - overall happy as long as it works!

some of the plan_yaml_generator stuff can be cleaned up but we can get to it in our own time.

@tedim52 tedim52 enabled auto-merge March 13, 2024 14:29
@tedim52 tedim52 added this pull request to the merge queue Mar 13, 2024
@tedim52 tedim52 removed this pull request from the merge queue due to a manual request Mar 13, 2024
@tedim52 tedim52 enabled auto-merge March 13, 2024 18:18
@tedim52 tedim52 added this pull request to the merge queue Mar 13, 2024
Merged via the queue into main with commit 2292010 Mar 13, 2024
51 of 52 checks passed
@tedim52 tedim52 deleted the tedi/dryrun branch March 13, 2024 18:41
@laurentluce laurentluce removed their request for review March 13, 2024 18:46
tedim52 added a commit that referenced this pull request Mar 13, 2024
## Description:
This PR adds package nodes to the enclave builder UI. It's based on the
backend work added by @tedim52 in #2177.

### Demo
This demo has two paths - the first one shows how a package can be added
to the enclave builder, and used by a service defined in the builder as
a dependency. The second one shows how two packages can be combined in
the same enclave - allowing connectivity between them at runtime.


https://github.com/kurtosis-tech/kurtosis/assets/4419574/64ed2b91-1565-49ed-841b-c655dd6b28f9

## Is this change user facing?
YES

## References (if applicable):
- Discussion on slack.

---------

Co-authored-by: Tedi Mitiku <tedi.m52@gmail.com>
github-merge-queue bot pushed a commit that referenced this pull request Mar 13, 2024
🤖 I have created a release *beep* *boop*
---


##
[0.88.6](0.88.5...0.88.6)
(2024-03-13)


### Features

* define `build_args` in `ImageBuildSpec`
([#2257](#2257))
([9812375](9812375))
* generate plan yamls
([#2177](#2177))
([2292010](2292010))
* port guessing based on port number for docker transpiler
([#2281](#2281))
([5c98ce2](5c98ce2))
* support package nodes in enclave builder ui
([#2283](#2283))
([7fa27ed](7fa27ed))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: kurtosisbot <kurtosisbot@users.noreply.github.com>
tedim52 added a commit that referenced this pull request Mar 21, 2024
## Description:

This change implements the generation of a yaml that represents the
effect of a sequence of instructions on an enclave. The major changes
are as follows:

- Adds gRPC endpoints `GetStarlarkPackge/ScriptPlanYaml` to APIC and
Enclave Manager for returning this yaml
- Implements `PlanYaml` object and yaml generation logic in
`startosis_engine`
- Adds `UpdatePlan(plan *PlanYaml)` method to `KurtosisInstruction`
interface so each instruction implements logic for updating the plan
yaml
- Most of the knowledge needed to generate the yaml comes from the
interpretation phase and is simply passed into yaml generation logic

Tests are in `startosis_interpreter_plan_yaml_tests.go` and demonstrate
how the `InstructionsPlan` generates the yaml via the `PlanYaml` object.

eg. starlark script turned plan yaml:

```
def run(plan, hi_files_artifact):
	service = plan.add_service(
		name="db",
		config=ServiceConfig(
			image="postgres:latest",
			env_vars={
				"POSTGRES_DB": "kurtosis",
				"POSTGRES_USER": "kurtosis",
				"POSTGRES_PASSWORD": "kurtosis",
			},
			files = {
				"/root": hi_files_artifact,
			}
		)
	)
	execResult = plan.exec(
		service_name="db",
		recipe=ExecRecipe(
			command=["echo", service.ip_address + " " + service.hostname]
		),
		acceptable_codes=[0],
	)	
	runShResult = plan.run_sh(
		run="echo " + execResult["code"] + " " + execResult["output"],
	)
	plan.run_sh(
		run="echo " + runShResult.code + " " + runShResult.output,
	)
```
plan yaml:
```
packageId: DEFAULT_PACKAGE_ID_FOR_SCRIPT
services:
- uuid: "1"
  name: db
  image:
    name: postgres:latest
  envVars:
  - key: POSTGRES_DB
    value: kurtosis
  - key: POSTGRES_PASSWORD
    value: kurtosis
  - key: POSTGRES_USER
    value: kurtosis
  files:
  - mountPath: /root
    filesArtifacts:
    - uuid: "2"
      name: hi-file
filesArtifacts:
- uuid: "2"
  name: hi-file
tasks:
- uuid: "3"
  taskType: exec
  command:
  - echo
  - '{{ kurtosis.1.ip_address }} {{ kurtosis.1.hostname }}'
  serviceName: db
  acceptableCodes:
  - 0
- uuid: "4"
  taskType: sh
  command:
  - echo {{ kurtosis.3.code }} {{ kurtosis.3.output }}
  image: badouralix/curl-jq
- uuid: "5"
  taskType: sh
  command:
  - echo {{ kurtosis.4.code }} {{ kurtosis.4.output }}
  image: badouralix/curl-jq
  ```


## Is this change user facing?
NO

## References:

The Enclave Manager uses this plan yaml to render packages in the Enclave Builder:
#2250

---------

Co-authored-by: Ben Gazzard <ben@dartoxia.com>
tedim52 pushed a commit that referenced this pull request Mar 21, 2024
🤖 I have created a release *beep* *boop*
---


##
[0.88.6](0.88.5...0.88.6)
(2024-03-13)


### Features

* define `build_args` in `ImageBuildSpec`
([#2257](#2257))
([9812375](9812375))
* generate plan yamls
([#2177](#2177))
([2292010](806a13e))
* port guessing based on port number for docker transpiler
([#2281](#2281))
([5c98ce2](e20fb32))
* support package nodes in enclave builder ui
([#2283](#2283))
([7fa27ed](3c25691))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: kurtosisbot <kurtosisbot@users.noreply.github.com>
tedim52 added a commit that referenced this pull request Mar 21, 2024
## Description:

This change implements the generation of a yaml that represents the
effect of a sequence of instructions on an enclave. The major changes
are as follows:

- Adds gRPC endpoints `GetStarlarkPackge/ScriptPlanYaml` to APIC and
Enclave Manager for returning this yaml
- Implements `PlanYaml` object and yaml generation logic in
`startosis_engine`
- Adds `UpdatePlan(plan *PlanYaml)` method to `KurtosisInstruction`
interface so each instruction implements logic for updating the plan
yaml
- Most of the knowledge needed to generate the yaml comes from the
interpretation phase and is simply passed into yaml generation logic

Tests are in `startosis_interpreter_plan_yaml_tests.go` and demonstrate
how the `InstructionsPlan` generates the yaml via the `PlanYaml` object.

eg. starlark script turned plan yaml:

```
def run(plan, hi_files_artifact):
	service = plan.add_service(
		name="db",
		config=ServiceConfig(
			image="postgres:latest",
			env_vars={
				"POSTGRES_DB": "kurtosis",
				"POSTGRES_USER": "kurtosis",
				"POSTGRES_PASSWORD": "kurtosis",
			},
			files = {
				"/root": hi_files_artifact,
			}
		)
	)
	execResult = plan.exec(
		service_name="db",
		recipe=ExecRecipe(
			command=["echo", service.ip_address + " " + service.hostname]
		),
		acceptable_codes=[0],
	)	
	runShResult = plan.run_sh(
		run="echo " + execResult["code"] + " " + execResult["output"],
	)
	plan.run_sh(
		run="echo " + runShResult.code + " " + runShResult.output,
	)
```
plan yaml:
```
packageId: DEFAULT_PACKAGE_ID_FOR_SCRIPT
services:
- uuid: "1"
  name: db
  image:
    name: postgres:latest
  envVars:
  - key: POSTGRES_DB
    value: kurtosis
  - key: POSTGRES_PASSWORD
    value: kurtosis
  - key: POSTGRES_USER
    value: kurtosis
  files:
  - mountPath: /root
    filesArtifacts:
    - uuid: "2"
      name: hi-file
filesArtifacts:
- uuid: "2"
  name: hi-file
tasks:
- uuid: "3"
  taskType: exec
  command:
  - echo
  - '{{ kurtosis.1.ip_address }} {{ kurtosis.1.hostname }}'
  serviceName: db
  acceptableCodes:
  - 0
- uuid: "4"
  taskType: sh
  command:
  - echo {{ kurtosis.3.code }} {{ kurtosis.3.output }}
  image: badouralix/curl-jq
- uuid: "5"
  taskType: sh
  command:
  - echo {{ kurtosis.4.code }} {{ kurtosis.4.output }}
  image: badouralix/curl-jq
  ```


## Is this change user facing?
NO

## References:

The Enclave Manager uses this plan yaml to render packages in the Enclave Builder:
#2250

---------

Co-authored-by: Ben Gazzard <ben@dartoxia.com>
tedim52 pushed a commit that referenced this pull request Mar 21, 2024
🤖 I have created a release *beep* *boop*
---


##
[0.88.6](0.88.5...0.88.6)
(2024-03-13)


### Features

* define `build_args` in `ImageBuildSpec`
([#2257](#2257))
([9812375](9812375))
* generate plan yamls
([#2177](#2177))
([2292010](e157686))
* port guessing based on port number for docker transpiler
([#2281](#2281))
([5c98ce2](3a32230))
* support package nodes in enclave builder ui
([#2283](#2283))
([7fa27ed](0b2395d))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: kurtosisbot <kurtosisbot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants