diff --git a/docs/docs/api-reference/cassandra.md b/docs/docs/api-reference/cassandra.md index 2a925b96..8b214758 100644 --- a/docs/docs/api-reference/cassandra.md +++ b/docs/docs/api-reference/cassandra.md @@ -40,6 +40,24 @@ title: "Cassandra" - network: 10.20.0.0/16 ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `Cassandra`: + +```shell +kubectl get cassandras my-cassandra +``` + +The output is similar to the following: +```shell +Name Project Region Plan State +my-cassandra aiven-project-name google-europe-west1 startup-4 RUNNING +``` + ## Cassandra {: #Cassandra } Cassandra is the Schema for the cassandras API. diff --git a/docs/docs/api-reference/clickhouse.md b/docs/docs/api-reference/clickhouse.md index e651b215..0a0fe67f 100644 --- a/docs/docs/api-reference/clickhouse.md +++ b/docs/docs/api-reference/clickhouse.md @@ -40,6 +40,24 @@ title: "Clickhouse" maintenanceWindowTime: 23:00:00 ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `Clickhouse`: + +```shell +kubectl get clickhouses my-clickhouse +``` + +The output is similar to the following: +```shell +Name Project Region Plan State +my-clickhouse my-aiven-project google-europe-west1 startup-16 RUNNING +``` + ## Clickhouse {: #Clickhouse } Clickhouse is the Schema for the clickhouses API. diff --git a/docs/docs/api-reference/clickhousedatabase.md b/docs/docs/api-reference/clickhousedatabase.md index 0badec5d..81972d47 100644 --- a/docs/docs/api-reference/clickhousedatabase.md +++ b/docs/docs/api-reference/clickhousedatabase.md @@ -20,6 +20,24 @@ title: "ClickhouseDatabase" databaseName: example-db ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `ClickhouseDatabase`: + +```shell +kubectl get clickhousedatabases my-db +``` + +The output is similar to the following: +```shell +Name Database name Service Name Project +my-db example-db my-clickhouse my-aiven-project +``` + ## ClickhouseDatabase {: #ClickhouseDatabase } ClickhouseDatabase is the Schema for the databases API. diff --git a/docs/docs/api-reference/clickhousegrant.md b/docs/docs/api-reference/clickhousegrant.md index 954601d5..08c6ca10 100644 --- a/docs/docs/api-reference/clickhousegrant.md +++ b/docs/docs/api-reference/clickhousegrant.md @@ -46,6 +46,24 @@ title: "ClickhouseGrant" - role: my-role ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `ClickhouseGrant`: + +```shell +kubectl get clickhousegrants demo-ch-grant +``` + +The output is similar to the following: +```shell +Name Project Service Name +demo-ch-grant my-aiven-project my-clickhouse +``` + ## ClickhouseGrant {: #ClickhouseGrant } ClickhouseGrant is the Schema for the ClickhouseGrants API. diff --git a/docs/docs/api-reference/clickhouserole.md b/docs/docs/api-reference/clickhouserole.md index 8963bfc2..55e5f098 100644 --- a/docs/docs/api-reference/clickhouserole.md +++ b/docs/docs/api-reference/clickhouserole.md @@ -20,6 +20,24 @@ title: "ClickhouseRole" role: my-role ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `ClickhouseRole`: + +```shell +kubectl get clickhouseroles my-role +``` + +The output is similar to the following: +```shell +Name Project Service Name Role +my-role my-aiven-project my-clickhouse my-role +``` + ## ClickhouseRole {: #ClickhouseRole } ClickhouseRole is the Schema for the clickhouseroles API. diff --git a/docs/docs/api-reference/clickhouseuser.md b/docs/docs/api-reference/clickhouseuser.md index 6fa5ee35..773599b6 100644 --- a/docs/docs/api-reference/clickhouseuser.md +++ b/docs/docs/api-reference/clickhouseuser.md @@ -42,6 +42,24 @@ title: "ClickhouseUser" plan: startup-16 ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `ClickhouseUser`: + +```shell +kubectl get clickhouseusers my-clickhouse-user +``` + +The output is similar to the following: +```shell +Name Username Service Name Project +my-clickhouse-user example-username my-clickhouse my-aiven-project +``` + ## ClickhouseUser {: #ClickhouseUser } ClickhouseUser is the Schema for the clickhouseusers API. diff --git a/docs/docs/api-reference/connectionpool.md b/docs/docs/api-reference/connectionpool.md index ea7301e3..f424b025 100644 --- a/docs/docs/api-reference/connectionpool.md +++ b/docs/docs/api-reference/connectionpool.md @@ -66,6 +66,24 @@ title: "ConnectionPool" serviceName: my-pg ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `ConnectionPool`: + +```shell +kubectl get connectionpools my-connection-pool +``` + +The output is similar to the following: +```shell +Name Service Name Project Database Username Pool Size Pool Mode +my-connection-pool my-pg aiven-project-name my-database my-service-user 25 transaction +``` + ## ConnectionPool {: #ConnectionPool } ConnectionPool is the Schema for the connectionpools API. diff --git a/docs/docs/api-reference/database.md b/docs/docs/api-reference/database.md index 5ea2e3a3..ab234051 100644 --- a/docs/docs/api-reference/database.md +++ b/docs/docs/api-reference/database.md @@ -22,6 +22,24 @@ title: "Database" lcCollate: en_US.UTF-8 ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `Database`: + +```shell +kubectl get databases my-db +``` + +The output is similar to the following: +```shell +Name Project Service Name +my-db aiven-project-name my-service +``` + ## Database {: #Database } Database is the Schema for the databases API. diff --git a/docs/docs/api-reference/grafana.md b/docs/docs/api-reference/grafana.md index bf0489f5..b91a8613 100644 --- a/docs/docs/api-reference/grafana.md +++ b/docs/docs/api-reference/grafana.md @@ -39,6 +39,24 @@ title: "Grafana" - network: 10.20.0.0/16 ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `Grafana`: + +```shell +kubectl get grafanas my-grafana +``` + +The output is similar to the following: +```shell +Name Project Region Plan State +my-grafana my-aiven-project google-europe-west1 startup-1 RUNNING +``` + ## Grafana {: #Grafana } Grafana is the Schema for the grafanas API. diff --git a/docs/docs/api-reference/kafka.md b/docs/docs/api-reference/kafka.md index 99a4cc0e..f0a686c8 100644 --- a/docs/docs/api-reference/kafka.md +++ b/docs/docs/api-reference/kafka.md @@ -31,6 +31,24 @@ title: "Kafka" maintenanceWindowTime: 23:00:00 ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `Kafka`: + +```shell +kubectl get kafkas my-kafka +``` + +The output is similar to the following: +```shell +Name Project Region Plan State +my-kafka my-aiven-project google-europe-west1 startup-2 RUNNING +``` + ## Kafka {: #Kafka } Kafka is the Schema for the kafkas API. diff --git a/docs/docs/api-reference/kafkaacl.md b/docs/docs/api-reference/kafkaacl.md index 0aa8b986..efb695e8 100644 --- a/docs/docs/api-reference/kafkaacl.md +++ b/docs/docs/api-reference/kafkaacl.md @@ -22,6 +22,24 @@ title: "KafkaACL" permission: admin ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `KafkaACL`: + +```shell +kubectl get kafkaacls my-kafka-acl +``` + +The output is similar to the following: +```shell +Name Service Name Project Username Permission Topic +my-kafka-acl my-kafka my-aiven-project my-user admin my-topic +``` + ## KafkaACL {: #KafkaACL } KafkaACL is the Schema for the kafkaacls API. diff --git a/docs/docs/api-reference/kafkaconnect.md b/docs/docs/api-reference/kafkaconnect.md index 2de83cc1..8a3cc3e3 100644 --- a/docs/docs/api-reference/kafkaconnect.md +++ b/docs/docs/api-reference/kafkaconnect.md @@ -26,6 +26,24 @@ title: "KafkaConnect" kafka_connect: true ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `KafkaConnect`: + +```shell +kubectl get kafkaconnects my-kafka-connect +``` + +The output is similar to the following: +```shell +Name Project Region Plan State +my-kafka-connect my-aiven-project google-europe-west1 business-4 RUNNING +``` + ## KafkaConnect {: #KafkaConnect } KafkaConnect is the Schema for the kafkaconnects API. diff --git a/docs/docs/api-reference/kafkaschema.md b/docs/docs/api-reference/kafkaschema.md index 849dca9c..a44d9a43 100644 --- a/docs/docs/api-reference/kafkaschema.md +++ b/docs/docs/api-reference/kafkaschema.md @@ -35,6 +35,24 @@ title: "KafkaSchema" } ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `KafkaSchema`: + +```shell +kubectl get kafkaschemas my-schema +``` + +The output is similar to the following: +```shell +Name Service Name Project Subject Compatibility Level Version +my-schema my-kafka my-aiven-project mny-subject BACKWARD +``` + ## KafkaSchema {: #KafkaSchema } KafkaSchema is the Schema for the kafkaschemas API. diff --git a/docs/docs/api-reference/kafkaschemaregistryacl.md b/docs/docs/api-reference/kafkaschemaregistryacl.md index a29104d9..58576915 100644 --- a/docs/docs/api-reference/kafkaschemaregistryacl.md +++ b/docs/docs/api-reference/kafkaschemaregistryacl.md @@ -22,6 +22,24 @@ title: "KafkaSchemaRegistryACL" permission: schema_registry_read ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `KafkaSchemaRegistryACL`: + +```shell +kubectl get kafkaschemaregistryacls my-kafka-schema-registry-acl +``` + +The output is similar to the following: +```shell +Name Project Service Name Resource Username State +my-kafka-schema-registry-acl aiven-project-name my-kafka Subject:my-topic my-user RUNNING +``` + ## KafkaSchemaRegistryACL {: #KafkaSchemaRegistryACL } KafkaSchemaRegistryACL is the Schema for the kafkaschemaregistryacls API. diff --git a/docs/docs/api-reference/kafkatopic.md b/docs/docs/api-reference/kafkatopic.md index 73191281..28bd8b0c 100644 --- a/docs/docs/api-reference/kafkatopic.md +++ b/docs/docs/api-reference/kafkatopic.md @@ -26,6 +26,24 @@ title: "KafkaTopic" min_cleanable_dirty_ratio: 0.2 ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `KafkaTopic`: + +```shell +kubectl get kafkatopics kafka-topic +``` + +The output is similar to the following: +```shell +Name Service Name Project Partitions Replication +kafka-topic my-kafka my-aiven-project 1 2 +``` + ## KafkaTopic {: #KafkaTopic } KafkaTopic is the Schema for the kafkatopics API. diff --git a/docs/docs/api-reference/mysql.md b/docs/docs/api-reference/mysql.md index 542f2f20..6b5810c3 100644 --- a/docs/docs/api-reference/mysql.md +++ b/docs/docs/api-reference/mysql.md @@ -39,6 +39,24 @@ title: "MySQL" - network: 10.20.0.0/16 ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `MySQL`: + +```shell +kubectl get mysqls my-mysql +``` + +The output is similar to the following: +```shell +Name Project Region Plan State +my-mysql my-aiven-project google-europe-west1 business-4 RUNNING +``` + ## MySQL {: #MySQL } MySQL is the Schema for the mysqls API. diff --git a/docs/docs/api-reference/opensearch.md b/docs/docs/api-reference/opensearch.md index d88837d1..d6e91939 100644 --- a/docs/docs/api-reference/opensearch.md +++ b/docs/docs/api-reference/opensearch.md @@ -32,6 +32,24 @@ title: "OpenSearch" maintenanceWindowTime: 23:00:00 ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `OpenSearch`: + +```shell +kubectl get opensearches my-os +``` + +The output is similar to the following: +```shell +Name Project Region Plan State +my-os my-aiven-project google-europe-west1 startup-4 RUNNING +``` + ## OpenSearch {: #OpenSearch } OpenSearch is the Schema for the opensearches API. diff --git a/docs/docs/api-reference/postgresql.md b/docs/docs/api-reference/postgresql.md index 88c20446..2738449b 100644 --- a/docs/docs/api-reference/postgresql.md +++ b/docs/docs/api-reference/postgresql.md @@ -34,6 +34,24 @@ title: "PostgreSQL" pg_version: "15" ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `PostgreSQL`: + +```shell +kubectl get postgresqls my-postgresql +``` + +The output is similar to the following: +```shell +Name Project Region Plan State +my-postgresql aiven-project-name google-europe-west1 startup-4 RUNNING +``` + ## PostgreSQL {: #PostgreSQL } PostgreSQL is the Schema for the postgresql API. diff --git a/docs/docs/api-reference/project.md b/docs/docs/api-reference/project.md index e2bc64c5..65e7bf00 100644 --- a/docs/docs/api-reference/project.md +++ b/docs/docs/api-reference/project.md @@ -30,6 +30,24 @@ title: "Project" cloud: aws-eu-west-1 ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `Project`: + +```shell +kubectl get projects my-project +``` + +The output is similar to the following: +```shell +Name +my-project +``` + ## Project {: #Project } Project is the Schema for the projects API. diff --git a/docs/docs/api-reference/projectvpc.md b/docs/docs/api-reference/projectvpc.md index 753b0239..97848efd 100644 --- a/docs/docs/api-reference/projectvpc.md +++ b/docs/docs/api-reference/projectvpc.md @@ -20,6 +20,24 @@ title: "ProjectVPC" networkCidr: 10.0.0.0/24 ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `ProjectVPC`: + +```shell +kubectl get projectvpcs my-project-vpc +``` + +The output is similar to the following: +```shell +Name Project Cloud Network CIDR State +my-project-vpc aiven-project-name google-europe-west1 10.0.0.0/24 RUNNING +``` + ## ProjectVPC {: #ProjectVPC } ProjectVPC is the Schema for the projectvpcs API. diff --git a/docs/docs/api-reference/redis.md b/docs/docs/api-reference/redis.md index 7276be2b..4617d88b 100644 --- a/docs/docs/api-reference/redis.md +++ b/docs/docs/api-reference/redis.md @@ -34,6 +34,24 @@ title: "Redis" redis_maxmemory_policy: allkeys-random ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `Redis`: + +```shell +kubectl get redis k8s-redis +``` + +The output is similar to the following: +```shell +Name Project Region Plan State +k8s-redis my-aiven-project google-europe-west1 startup-4 RUNNING +``` + ## Redis {: #Redis } Redis is the Schema for the redis API. diff --git a/docs/docs/api-reference/serviceintegration.md b/docs/docs/api-reference/serviceintegration.md index 457b4758..2a90cb85 100644 --- a/docs/docs/api-reference/serviceintegration.md +++ b/docs/docs/api-reference/serviceintegration.md @@ -208,6 +208,24 @@ title: "ServiceIntegration" partitions: 1 ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `ServiceIntegration`: + +```shell +kubectl get serviceintegrations my-service-integration +``` + +The output is similar to the following: +```shell +Name Project Type Source Service Name Destination Service Name +my-service-integration aiven-project-name clickhouse_postgresql my-pg my-clickhouse +``` + ## ServiceIntegration {: #ServiceIntegration } ServiceIntegration is the Schema for the serviceintegrations API. diff --git a/docs/docs/api-reference/serviceintegrationendpoint.md b/docs/docs/api-reference/serviceintegrationendpoint.md index 025b5445..cb40ca17 100644 --- a/docs/docs/api-reference/serviceintegrationendpoint.md +++ b/docs/docs/api-reference/serviceintegrationendpoint.md @@ -49,6 +49,24 @@ title: "ServiceIntegrationEndpoint" basic_auth_password: password ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `ServiceIntegrationEndpoint`: + +```shell +kubectl get serviceintegrationendpoints my-service-integration-endpoint +``` + +The output is similar to the following: +```shell +Name Project Endpoint Name Endpoint Type ID +my-service-integration-endpoint aiven-project-name my-external-postgresql external_postgresql +``` + ## ServiceIntegrationEndpoint {: #ServiceIntegrationEndpoint } ServiceIntegrationEndpoint is the Schema for the serviceintegrationendpoints API. diff --git a/docs/docs/api-reference/serviceuser.md b/docs/docs/api-reference/serviceuser.md index 40513576..52534457 100644 --- a/docs/docs/api-reference/serviceuser.md +++ b/docs/docs/api-reference/serviceuser.md @@ -27,6 +27,24 @@ title: "ServiceUser" serviceName: my-service-name ``` +Apply the resource with: + +```shell +kubectl apply -f example.yaml +``` + +Verify the newly created `ServiceUser`: + +```shell +kubectl get serviceusers my-service-user +``` + +The output is similar to the following: +```shell +Name Service Name Project +my-service-user my-service-name aiven-project-name +``` + ## ServiceUser {: #ServiceUser } ServiceUser is the Schema for the serviceusers API. diff --git a/generators/docs/generator.go b/generators/docs/generator.go index 6eb7a38c..b2731078 100644 --- a/generators/docs/generator.go +++ b/generators/docs/generator.go @@ -40,6 +40,8 @@ func parseSchema(crdData []byte) (*schemaType, error) { kind.Name = kind.Kind kind.Version = crd.Spec.Versions[0].Name kind.Group = crd.Spec.Group + kind.Plural = crd.Spec.Names.Plural + kind.Columns = crd.Spec.Versions[0].AdditionalPrinterColumns // Those fields are generic, but can have only explicit values kind.Properties["apiVersion"].Description = fmt.Sprintf("Value `%s/%s`", kind.Group, kind.Version) @@ -73,13 +75,15 @@ type crdType struct { Spec struct { Group string `yaml:"group"` Names struct { - Kind string `yaml:"kind"` + Kind string `yaml:"kind"` + Plural string `yaml:"plural"` } `yaml:"names"` Versions []struct { Name string `yaml:"name"` Schema struct { OpenAPIV3Schema *schemaType `yaml:"openAPIV3Schema"` } `yaml:"schema"` + AdditionalPrinterColumns []specTableColumn `yaml:"additionalPrinterColumns"` } `yaml:"versions"` } `yaml:"spec"` } @@ -88,6 +92,13 @@ type usageExample struct { Title, Value string } +// specTableColumn the column fields printed on "kubectl get foo name" command +type specTableColumn struct { + Name string `yaml:"name"` + Type string `yaml:"type"` + Path string `yaml:"jsonPath"` +} + type schemaInternal struct { // Internal parent *schemaType // parent line @@ -100,6 +111,8 @@ type schemaInternal struct { Name string // field name Version string // API version, like v1alpha Group string // API group, like aiven.io + Plural string + Columns []specTableColumn UsageExamples []usageExample } @@ -319,6 +332,71 @@ func (s *schemaType) GetDef() string { return strings.Join(chunks, ", ") } +// exampleType example.yaml files model +type exampleType struct { + Kind string `yaml:"kind"` + Metadata struct { + Name string `yaml:"name"` + } + Spec map[string]any `yaml:"spec"` + Table []exampleTableColumn +} + +// exampleTableColumn columns and values from the exampleType +type exampleTableColumn struct { + Title, Value string +} + +// GetExample returns exampleType with formed output table +func (s *schemaType) GetExample() *exampleType { + var example *exampleType + for _, e := range loadYAMLs[exampleType]([]byte(s.UsageExamples[0].Value)) { + if e.Kind == s.Kind { + example = e + break + } + } + + if example == nil { + return nil + } + + // Adds the Name column + example.Table = append(example.Table, exampleTableColumn{Title: "Name", Value: example.Metadata.Name}) + + // Takes columns from the spec and values from the example + for _, c := range s.Columns { + column := exampleTableColumn{} + if strings.HasPrefix(c.Path, ".spec.") { + k := strings.TrimPrefix(c.Path, ".spec.") + column.Value = fmt.Sprintf("%v", example.Spec[k]) + } else { + switch c.Path { + case ".status.state": + column.Value = "RUNNING" + default: + column.Value = fmt.Sprintf("<%s>", strings.TrimPrefix(c.Path, ".status.")) + } + } + + switch column.Value { + case "", "": + // Not set + continue + } + + column.Title = c.Name + example.Table = append(example.Table, column) + } + + return example +} + +// rfill adds right padding +func rfill(x, y string) string { + return fmt.Sprintf("%-*s", max(len(x), len(y)), x) +} + var reIndent = regexp.MustCompile("(?m)^") var templateFuncs = template.FuncMap{ @@ -326,11 +404,10 @@ var templateFuncs = template.FuncMap{ return reIndent.ReplaceAllString(src, strings.Repeat(" ", i)) }, "backtick": func(i int) string { + // we can't use backticks in go strings, so we render them return strings.Repeat("`", i) }, - "add": func(x, y int) int { - return x + y - }, + "rfill": rfill, } const schemaTemplate = `--- @@ -346,6 +423,27 @@ title: "{{ .Kind }}" {{ .Value | indent 4 }} {{ backtick 3 }} {{ end }} + +{{ $example := .GetExample }} +{{ if $example }} +Apply the resource with: + +{{ backtick 3 }}shell +kubectl apply -f example.yaml +{{ backtick 3 }} + +Verify the newly created {{ backtick 1 }}{{ .Kind }}{{ backtick 1 }}: + +{{ backtick 3 }}shell +kubectl get {{ .Plural }} {{ $example.Metadata.Name }} +{{ backtick 3 }} + +The output is similar to the following: +{{ backtick 3 }}shell +{{ range $example.Table }}{{ rfill .Title .Value }} {{ end }} +{{ range $example.Table }}{{ rfill .Value .Title }} {{ end }} +{{ backtick 3 }} +{{ end }} {{ end }} {{- template "renderSchema" . -}} @@ -404,3 +502,19 @@ func prettyDigit(kind string, value float64) string { s = reTrailingZeros.ReplaceAllString(s, "$1") return strings.TrimSuffix(s, ".") } + +// loadYAMLs loads a list of yamls +func loadYAMLs[T any](b []byte) []*T { + decoder := yaml.NewDecoder(bytes.NewReader(b)) + list := make([]*T, 0) + for { + doc := new(T) + err := decoder.Decode(&doc) + if err != nil { + break + } + + list = append(list, doc) + } + return list +}