{"id":24637981,"url":"https://github.com/upbound/function-cidr","last_synced_at":"2025-05-08T23:45:09.464Z","repository":{"id":210155034,"uuid":"645991453","full_name":"upbound/function-cidr","owner":"upbound","description":"Composition Function that transforms CIDRs","archived":false,"fork":false,"pushed_at":"2025-05-04T22:45:49.000Z","size":103,"stargazers_count":7,"open_issues_count":14,"forks_count":5,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-05-08T23:45:00.322Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/upbound.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-05-27T00:25:17.000Z","updated_at":"2024-10-10T13:57:28.000Z","dependencies_parsed_at":"2023-12-01T04:28:19.726Z","dependency_job_id":"31cbe1fc-3454-40cc-9f41-f84afbb831da","html_url":"https://github.com/upbound/function-cidr","commit_stats":null,"previous_names":["upbound/function-cidr"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upbound%2Ffunction-cidr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upbound%2Ffunction-cidr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upbound%2Ffunction-cidr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/upbound%2Ffunction-cidr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/upbound","download_url":"https://codeload.github.com/upbound/function-cidr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253166473,"owners_count":21864467,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2025-01-25T10:12:44.020Z","updated_at":"2025-05-08T23:45:09.448Z","avatar_url":"https://github.com/upbound.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# function-cidr\n\nA [Crossplane](https://www.crossplane.io/)\n[Composition Function](https://docs.crossplane.io/latest/concepts/composition-functions/)\nfor calculating Classless Inter-Domain Routing\n([CIDR](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing))\nnumbers.\n\nA CIDR is an IP address allocation method that is used to improve\ndata routing efficiency on the internet.\n\n## Overview\n\nThis composition function offers 4 HashiCorp compatible IP Network Functions\nplus two custom wrappers. Follow the function links for detailed explanations of\nthe function semantics.\n\n- [cidrhost](https://developer.hashicorp.com/terraform/language/functions/cidrhost)\n- [cidrnetmask](https://developer.hashicorp.com/terraform/language/functions/cidrnetmask)\n- [cidrsubnet](https://developer.hashicorp.com/terraform/language/functions/cidrsubnet)\n- [cidrsubnets](https://developer.hashicorp.com/terraform/language/functions/cidrsubnets)\n- cidrsubnetloop wraps [cidrsubnet](https://developer.hashicorp.com/terraform/language/functions/cidrsubnet)\n- multiprefixloop wraps [cidrsubnets](https://developer.hashicorp.com/terraform/language/functions/cidrsubnets)\n\nTo use this function, apply the following\n[functions.yaml](examples/functions.yaml)\nto your Crossplane management cluster.\n\n```bash\ncat \u003c\u003cEOF|kubectl apply -f -\napiVersion: pkg.crossplane.io/v1beta1\nkind: Function\nmetadata:\n  name: upbound-function-cidr\nspec:\n  package: xpkg.upbound.io/upbound/function-cidr:v0.4.0\nEOF\n```\n\nCall the function from a Crossplane composition as described below.\n\n## Terminology\n\nThe `cidrfunc` IP Network Functions have various input parameters.\nBelow are brief descriptions for context.\n\n- `prefix` must be given in CIDR notation, as defined in [RFC 4632 section 3.1.](https://datatracker.ietf.org/doc/html/rfc4632#section-3.1)\n- `hostnum` is a whole number that can be represented as a binary integer with\n  no more than the number of digits remaining in the address after the given\n  prefix.\n- `newbits` is the number of additional bits with which to extend the prefix.\n  For example, if given a prefix ending in /16 and a newbits value of 4, the\n  resulting subnet address will have length /20.\n- `netnum` is a whole number that can be represented as a binary integer with no\n  more than newbits binary digits, which will be used to populate the additional\n  bits added to the prefix.\n\n## Usage\n\nSpecify the `cidrfunc` calculation type in the composition function input.\n\nValid values are as follows:\n\n```yaml\n- cidrhost\n- cidrnetmask\n- cidrsubnet\n- cidrsubnets\n- cidrsubnetloop\n- multiprefixloop\n```\n\nSpecify a custom `outputField` in the function input parameters when the output\nshould appear at a different path than the respective `status.atFunction.cidr`\nsub field default path.\n\nAll `cidrfunc` IP Network Functions require a CIDR `prefix` as input.\n\nProvide the `prefix` directly in the function input or specify a `prefixField`\nin the XR where the function shall pick up the `prefix` value.\n\nFunction input field names ending in `Field` indicate that the function shall\nread the field path value from the specified field path in the XR.\n\nYou can also provide `desired.composite.resource.` and `desired.resources.` in the `prefixField` value to reference\nthe resource attribute from where to read the prefix value. See [apis/composition-pipeline.yaml](apis/composition-pipeline.yaml).\nIn addition, referencing the pipeline `context` is supported. You can use [gjson](https://github.com/tidwall/gjson)\nfor selecting context values. See [apis/composition-pipeline-context.yaml](apis/composition-pipeline-context.yaml).\n\n### cidrhost\n\nThe `cidrhost cidrfunc` requires a `hostnum` or `hostnumField` as\nfunction input. `hostnum` is an integer.\n\n### cidrnetmask\n\nThe `cidrnetmask cidrfunc` does not require additional parameters beyond the\n`prefix`. The `prefix` can be read from an XR field when the `prefixField` path\nis specified in the function input instead of a `prefix` value.\n\n### cidrsubnet\n\nThe `cidrhost cidrsubnet` requires a `netnum` or `netnumfield`, and a `newbits`\nor `newbitsfield` as function input.\n\n`netNum` is an integer.\n`newBits` is one integer in an array of integers.\n\n### cidrsubnets\n\nThe `cidrhost cidrsubnets` requires a `newBits` or `newBitsField` as function\ninput.\n\n`newBits` is an array of integers.\n\n### cidrsubnetloop\n\nThe `cidrhost cidrsubnetloop` requires the following input fields.\n\n- `newBits` (integer array) or `newBitsField`\n- `netNumCount` (integer) or `netNumCountField`\n- `netNumItems` (string array) or `netNumItemsField`\n- `offset` or `offsetField`\n\n**`netNumCount` and `netNumItems` are mutually exclusive**\n\nThe `cidrsubnetloop` wrapper calculates `cidrsubnet` CIDRs using\nthe `prefix` and `newBits` parameters as input. It performs the\ncalculations in a loop. The `netnum` is calculated during each\niteration from `iteration`+`offset`. The iterations are either from\n0 to `netNumCount` -1 or from 0 to number of items in `netNumItemsCount`\nor their respective values from their XR field references.\n\n### multiprefixloop\n\nThis is an additional convenience function that takes a list of objects, each\ndescribing a cidr prefix to split and returns the result as a\n`map[string][]string` key'd on the prefix for that block.\n\nIt is most useful for scenarios where your composition requires multiple cidr\nprefixes, such as splitting VPC additional CIDRs for subnet creation.\n\nThe `multiprefixloop` function requires a list of inputs with each input\ncontaining:\n\n- `prefix` The CIDR prefix to create subnets for\n- `newBits` An integer array defining how to split the prefix\n- `offset` An optional bit size to start the subnet range after\n\nIf `offset` is specified, this is prepended to the `newBits` field immediately\nbefore calculations and then removed after the calculation is completed.\n\n## Testing The Function\n\nClone the repo. Run `make debug` and in a second terminal run `make render`\nor `make render-pipeline` and examine the output. Corresponding compositions and XR\nyaml can be found in the `examples` folder.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fupbound%2Ffunction-cidr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fupbound%2Ffunction-cidr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fupbound%2Ffunction-cidr/lists"}