{"id":34222556,"url":"https://github.com/covarity/anchorctl","last_synced_at":"2026-03-10T20:33:35.073Z","repository":{"id":125746070,"uuid":"221648848","full_name":"covarity/anchorctl","owner":"covarity","description":"CLI tool for Kubernetes and Distributed System testing","archived":false,"fork":false,"pushed_at":"2020-03-24T08:21:52.000Z","size":43329,"stargazers_count":10,"open_issues_count":3,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2026-01-13T18:26:52.510Z","etag":null,"topics":["cobra","go","golang","kubernetes","testing"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/covarity.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-11-14T08:33:55.000Z","updated_at":"2020-03-23T10:34:53.000Z","dependencies_parsed_at":"2023-07-15T08:23:41.649Z","dependency_job_id":null,"html_url":"https://github.com/covarity/anchorctl","commit_stats":null,"previous_names":["anchorageio/anchorctl"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/covarity/anchorctl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/covarity%2Fanchorctl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/covarity%2Fanchorctl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/covarity%2Fanchorctl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/covarity%2Fanchorctl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/covarity","download_url":"https://codeload.github.com/covarity/anchorctl/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/covarity%2Fanchorctl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30352880,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T15:55:29.454Z","status":"ssl_error","status_checked_at":"2026-03-10T15:54:58.440Z","response_time":106,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cobra","go","golang","kubernetes","testing"],"created_at":"2025-12-15T23:44:58.484Z","updated_at":"2026-03-10T20:33:35.057Z","avatar_url":"https://github.com/covarity.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- [![codecov](https://codecov.io/gh/trussio/anchorctl/branch/master/graph/badge.svg)](https://codecov.io/gh/trussio/anchorctl) --\u003e\n[![Go Report Card](https://goreportcard.com/badge/github.com/covarity/anchorctl)](https://goreportcard.com/report/github.com/covarity/anchorctl)\n\n\n# Anchorctl\n\nAnchorctl is a command line utility that enables a test driven approach to developing distributed systems like Kubernetes. The utility\nworks in conjunction with Anchor kubernetes controller (Under development) to create a CRD based user experience for testing systems.\n\nThe kinds of tests supported are:\n- KubeTest: A collection of tests that are specifically related to the Kubernetes Ecosystem such as asserting the\nfunctionality of admission controllers, asserting the value of jsonpaths, and testing networkpolicies (under development).\n\n\n## Installation\n\n### Binary\n\nThe following make entry point build the application and produces a binary.\n\n```bash\nmake run\n```\n\n### Docker\n\nThe following make entry point builds a docker image of `anchorctl`. The latest CI build version of the utility can be taken from `docker.pkg.github.com/trussio/anchorctl/anchorctl`\n\n```bash\nmake docker\n```\n\n## Resources\n\nResources provide common mechanisms to refer to an object or a file.\n\n### Manifests\n\nManifests contain the following fields:\n- Path: Relative path to the file with kube resources\n- Action: \"CREATE\", \"UPDATE\" or \"DELETE\" action to apply to the file\n\n### ObjectRefs\n\nObjectRefs provide an interface to communicate with existing objects in the cluster. ObjectRef contains the following fields:\n```yaml\ntype: \"Resource\"\nspec:\n    kind: Pod # Kind of kubernetes resource to look for\n    namespace: default # Namespace of the resource\n    labels:\n      hello: world # Label value of the resource\n```\n\nWith the above information, `anchorctl` is able to find the object from a cluster.\n\n### Lifecycle\n\nSimilar to the Pod lifecycle, `anchorctl` support PostStart and PreStop hooks. These hooks can be used to set up your test environment such as create a testing namespace, etc.\n\n#### PostStart \u0026\u0026 PreStop\n\nPostStart is actioned before the tests are executed. PreStop is actioned after tests are executed and before program exits. The files are actioned on in the order they are structured.\n\nTake a list of Path and Action, such as:\n```yaml\nlifecycle:\n  # Runs before the tests\n  postStart:\n  - path: \"./samples/fixtures/applications-ns.yaml\"\n    action: \"CREATE\"\n  - path: \"./samples/fixtures/hello-world-nginx.yaml\"\n    action: \"CREATE\"\n  # Runs after the tests\n  preStop:\n  - path: \"./samples/fixtures/hello-world-nginx.yaml\"\n    action: \"DELETE\"\n  - path: \"./samples/fixtures/applications-ns.yaml\"\n    action: \"DELETE\"\n```\n\n![Lifecycle](./docs/assets/anchorctl-lifecycle.png)\n\n---\n\n## Tests\n\n### KubeTest\n\nKubeTest contains common functions to enable testing common kubernetes features.\n\nThe types of Kubernetes tests include:\n- `AssertJSONPath`: Takes a jsonpath and a value and asserts that the jsonpath of the objectRef in cluster is equal to the value.\nUsing this type of test, we can test the status of a deployment / pod, the number of replicas and anything else that is accessible in the yaml output of Kubernetes objects.\n\n```yaml\n# Assert that Pods in namespace applications with label hello=world is running the nginx docker image.\n- type: AssertJSONPath\n  spec:\n    jsonPath: \".spec.containers[0].image\"\n    value: \"nginx\"\n  resource:\n    objectRef:\n      type: Resource\n      spec:\n        kind: Pod\n        namespace: applications\n        labels:\n          hello: world\n```\n\n![AssertJSONPath](./docs/assets/assert-jsonpath.png)\n\n- `AssertValidation`: Used to ensure that the validation admission controller throw the expected error. Take a file and\nan action, applies the action to the file and assert that the error equals the expected error.\n\n```yaml\n# Assert that when attempting to create the resources in .resource.manifest.path, the error is returned by the API Server.\n- type: AssertValidation\n  spec:\n    containsResponse: \"External Loadbalancers cannot be deployed in this cluster\"\n  resource:\n    manifest:\n      path: \"./samples/fixtures/loadbalancer.yaml\"\n      action: CREATE\n```\n\n![AssertValidation](./docs/assets/assert-validation.png)\n\n- `AssertMutation`: Used to ensure that the mutating admission controller mutates the kubernetes object upon creation\nas expected.\n\n```yaml\n# Assert that after creating the resources in .resource.manifest.path, the function label of the object is equal to workload.\n- type: AssertMutation\n  spec:\n    jsonPath: \".metadata.labels.function\"\n    value: \"workload\"\n  resource:\n    manifest:\n      path: \"./samples/fixtures/deploy.yaml\"\n      action: CREATE\n\n```\n\n![AssertMutation](./docs/assets/assert-mutation.png)\n\n- `AssertExec`: Execute a command inside a container and assert that the output contains the expected string\n\n```yaml\n  - type: AssertExec\n    spec:\n      command:\n      - /opa\n      - version\n      contains: \"Version: 0.13.4\"\n    resource:\n      objectRef:\n        type: Resource\n        spec:\n          kind: Pod\n          namespace: opa\n          labels:\n            app: opa\n```\n\n### Prerequisites\n\n- go \u003e= 1.13\n- Kubernetes Cluster\n- kubectl\n\n## Why?\n\nWith the growing adoption of Kubernetes and increase in the number of varied services that runs inside, the issue of\nplatform validation and testing starts to emerge. With no easy mechanism to test, teams face the challenge of how to\ngain confidence with platform changes in an automated fashion.\n\nWe saw the necessity to build a solution to address the lack of distributed systems and application testing.\n\nThe vision for `anchorctl`:\n\n- Provide stability and reliability to the platform\n- Help with root cause analysis: first point of reference in case of failure\n- Understanding and validating network and service mesh topologies\n\n## Reference\n- Test OPA:\n    - [Anchor Test File](https://github.com/covarity/examples/blob/master/examples/test-admission-controller/test/anchor_test_ci.yaml)\n    - [Code](https://github.com/covarity/examples/blob/master/examples/test-admission-controller)\n- Kube Forum Sydney 2019 Talk:\n    - [Slides](https://github.com/covarity/demos/tree/master/kube-forum-2019)\n    - [Talk](https://youtu.be/tGDAuij5RvE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcovarity%2Fanchorctl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcovarity%2Fanchorctl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcovarity%2Fanchorctl/lists"}