Skip to content

Commit

Permalink
Fix sections in reference chapter (#413)
Browse files Browse the repository at this point in the history
* Remove println for ank apply

* Fix 'the the' wording issues

* Fix control interface user doc code
  • Loading branch information
inf17101 authored Nov 11, 2024
1 parent 55c9c23 commit 5b313ae
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

6 changes: 3 additions & 3 deletions agent/doc/swdesign/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ Status: approved

When handling existing workloads, for each found existing workload that is not in the provided list of initial workloads, the RuntimeManager shall request the RuntimeFacade to delete the workload.

Comment: If the the RuntimeManager finds an existing Workload that is not in the provided list of initial workloads, the Ankaios Agent shall stop the existing Workload. The Ankaios agent cannot consider the `DeleteCondition`s of the existing workload because the information is not available after an agent restart.
Comment: If the RuntimeManager finds an existing Workload that is not in the provided list of initial workloads, the Ankaios Agent shall stop the existing Workload. The Ankaios agent cannot consider the `DeleteCondition`s of the existing workload because the information is not available after an agent restart.

Tags:
- RuntimeManager
Expand Down Expand Up @@ -1975,7 +1975,7 @@ Needs:
Status: approved

When the podman runtime connector is called to create workload and the RuntimeFacade requests to mount the Control Interface pipes,
the podman runtime connector shall mount the the Control Interface pipes into the container in the file path `/run/ankaios/control_interface`.
the podman runtime connector shall mount the Control Interface pipes into the container in the file path `/run/ankaios/control_interface`.

Tags:
- ControlInterface
Expand Down Expand Up @@ -2196,7 +2196,7 @@ When the podman-kube runtime connector is called to create a workload and the po
the podman-kube runtime continues with applying the manifest and returning the workload ID.

Rationale:
The volumes are needed for a restart of the the agent, but are not necessary for the current execution of the agent.
The volumes are needed for a restart of the agent, but are not necessary for the current execution of the agent.
If the agent ignores the failure of creating of the volumes, the workloads can operate normally and only after a restart of the agent errors occur.
If the agent fails the start of a workload if it is not able to create the volumes, the workloads cannot operate currently and after a restart of the agent.

Expand Down
1 change: 0 additions & 1 deletion ank/src/cli_commands/apply_manifests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ pub fn parse_manifest(manifest: &mut InputSourcePair) -> Result<(Object, Vec<Pat
let obj_paths = Vec::<Path>::from(&obj);
for path in obj_paths {
let parts = path.parts();
println!("PATH PARTS: {:?}", parts);
if parts.len() > 1 {
let _ = &mut workload_paths
.insert(Path::from(format!("{}.{}", parts[0], parts[1])));
Expand Down
2 changes: 1 addition & 1 deletion doc/docs/reference/complete-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ workloadStates: []
agents: {}
```

It is not necessary to provide the whole structure of the the [CompleteState](./_ankaios.proto.md#completestate) data structure when using it in conjunction with the [object field mask](#object-field-mask). It is sufficient to provide the relevant branch of the [CompleteState](./_ankaios.proto.md#completestate) object. As an example, to change the restart behavior of the nginx workload, only the relevant branch of the [CompleteState](./_ankaios.proto.md#completestate) needs to be provided:
It is not necessary to provide the whole structure of the [CompleteState](./_ankaios.proto.md#completestate) data structure when using it in conjunction with the [object field mask](#object-field-mask). It is sufficient to provide the relevant branch of the [CompleteState](./_ankaios.proto.md#completestate) object. As an example, to change the restart behavior of the nginx workload, only the relevant branch of the [CompleteState](./_ankaios.proto.md#completestate) needs to be provided:

```bash
desiredState:
Expand Down
106 changes: 79 additions & 27 deletions doc/docs/reference/control-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,45 +122,68 @@ flowchart TD
Code snippet in [Rust](https://www.rust-lang.org/) for sending request message via control interface:

```rust
use api::ank_base::{Workload, RestartPolicy, Tag, UpdateStateRequest, Request, request::RequestContent, CompleteState, State};
use api::control_api::{ToAnkaios, to_ankaios::ToAnkaiosEnum};
use api::ank_base::{
request::RequestContent, CompleteState, Dependencies, Request, RestartPolicy, State, Tag, Tags,
UpdateStateRequest, Workload, WorkloadMap,
};
use api::control_api::{to_ankaios::ToAnkaiosEnum, Hello, ToAnkaios};
use prost::Message;
use std::{collections::HashMap, fs::File, io::Write, path::Path};

const ANKAIOS_CONTROL_INTERFACE_BASE_PATH: &str = "/run/ankaios/control_interface";
const REQUEST_ID: &str = "request_id";

fn create_update_workload_request() -> ToAnkaios {
let new_workloads = HashMap::from([(
"dynamic_nginx".to_string(),
Workload {
runtime: "podman".to_string(),
agent: "agent_A".to_string(),
restart_policy: RestartPolicy::Never.into(),
tags: vec![Tag {
key: "owner".to_string(),
value: "Ankaios team".to_string(),
}],
runtime_config: "image: docker.io/library/nginx\ncommandOptions: [\"-p\", \"8080:80\"]"
.to_string(),
dependencies: HashMap::new(),
},
)]);
fn create_hello_message() -> ToAnkaios {
ToAnkaios {
to_ankaios_enum: Some(ToAnkaiosEnum::Hello(Hello {
protocol_version: env!("ANKAIOS_VERSION").to_string(),
})),
}
}

fn create_request_to_add_new_workload() -> ToAnkaios {
let new_workloads = Some(WorkloadMap {
workloads: HashMap::from([(
"dynamic_nginx".to_string(),
Workload {
runtime: Some("podman".to_string()),
agent: Some("agent_A".to_string()),
restart_policy: Some(RestartPolicy::Never.into()),
tags: Some(Tags {
tags: vec![Tag {
key: "owner".to_string(),
value: "Ankaios team".to_string(),
}],
}),
runtime_config: Some(
"image: docker.io/library/nginx\ncommandOptions: [\"-p\", \"8080:80\"]"
.to_string(),
),
dependencies: Some(Dependencies {
dependencies: HashMap::new(),
}),
configs: None,
control_interface_access: None,
},
)]),
});

ToAnkaios {
to_ankaios_enum: Some(ToAnkaiosEnum::Request(Request {
request_id: "request_id".to_string(),
request_content: Some(RequestContent::UpdateStateRequest(
request_id: REQUEST_ID.to_string(),
request_content: Some(RequestContent::UpdateStateRequest(Box::new(
UpdateStateRequest {
new_state: Some(CompleteState {
desired_state: Some(State {
api_version: "v0.1".to_string(),
api_version: "v0.1".into(),
workloads: new_workloads,
..Default::default()
}),
..Default::default()
}),
update_mask: vec!["desiredState.workloads.dynamic_nginx".to_string()],
},
)),
))),
})),
}
}
Expand All @@ -171,10 +194,15 @@ fn write_to_control_interface() {

let mut sc_req = File::create(&sc_req_fifo).unwrap();

let protobuf_update_workload_request = create_update_workload_request();
let protobuf_hello_message = create_hello_message();
let protobuf_update_workload_request = create_request_to_add_new_workload();

println!("{}", &format!("Sending UpdateStateRequest containing details for adding the dynamic workload \"dynamic_nginx\": {:#?}", protobuf_update_workload_request));

sc_req
.write_all(&protobuf_hello_message.encode_length_delimited_to_vec())
.unwrap(); // send the initial hello message for establishing the connection

sc_req
.write_all(&protobuf_update_workload_request.encode_length_delimited_to_vec())
.unwrap();
Expand Down Expand Up @@ -212,10 +240,11 @@ flowchart TD
Code Snippet in [Rust](https://www.rust-lang.org/) for reading response message via control interface:

```rust
use api::control_api::FromAnkaios;
use api::control_api::{FromAnkaios, from_ankaios::FromAnkaiosEnum};
use prost::Message;
use std::{fs::File, io, io::Read, path::Path};

const REQUEST_ID: &str = "request_id";
const ANKAIOS_CONTROL_INTERFACE_BASE_PATH: &str = "/run/ankaios/control_interface";
const MAX_VARINT_SIZE: usize = 19;

Expand Down Expand Up @@ -253,9 +282,32 @@ fn read_from_control_interface() {

loop {
if let Ok(binary) = read_protobuf_data(&mut ex_req) {
let proto = FromAnkaios::decode(&mut Box::new(binary.as_ref()));

println!("{}", &format!("Received FromAnkaios message containing the response from the server: {:#?}", proto));
match FromAnkaios::decode(&mut Box::new(binary.as_ref())) {
Ok(from_ankaios) => {
let Some(FromAnkaiosEnum::Response(response)) = &from_ankaios.from_ankaios_enum
else {
println!("No response. Continue.");
continue;
};

// use the response if the request id matches
let request_id: &String = &response.request_id;
if response.request_id == REQUEST_ID {
println!(
"Received FromAnkaios message containing the response from the server: {:#?}",
from_ankaios
);
} else {
println!(
"RequestId does not match. Skipping messages from requestId: {}",
request_id
);
}
}
Err(err) => {
println!("Invalid response, parsing error: '{}'", err);
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion doc/docs/reference/startup-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ A workload specification must contain the following information:
* `workload name`_(via field key)_, specify the workload name to identify the workload in the Ankaios system.
* `runtime`, specify the type of the runtime. Currently supported values are `podman` and `podman-kube`.
* `agent`, specify the name of the owning agent which is going to execute the workload. Supports templated strings.
* `restartPolicy`, specify how the workload should be restarted upon exiting (not implemented yet).
* `restartPolicy`, specify how the workload should be restarted upon exiting.
* `tags`, specify a list of `key` `value` pairs.
* `runtimeConfig`, specify as a _string_ the configuration for the [runtime](./glossary.md#runtime) whose configuration structure is specific for each runtime, e.g., for `podman` runtime the [PodmanRuntimeConfig](#podmanruntimeconfig) is used. Supports templated strings.
* `configs`: assign configuration items defined in the state's `configs` field to the workload
Expand Down
2 changes: 1 addition & 1 deletion server/doc/swdesign/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ Needs:
Status: approved

When the Ankaios Server responses to a GetCompleteState request,
it includes the the RequestID from the GetCompleteState request.
it includes the RequestID from the GetCompleteState request.

Tags:
- ControlInterface
Expand Down

0 comments on commit 5b313ae

Please sign in to comment.