Skip to content

jacob-delgado/demo

Repository files navigation

Demo application

A demo K8s controller that listens for the custom resources based on the following CRD. Based on https://itnext.io/how-to-generate-client-codes-for-kubernetes-custom-resource-definitions-crd-b4b9907769ba and https://github.com/kubernetes/sample-controller

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: hellotypes.foo.com
spec:
  group: foo.com
  scope: Namespaced
  versions:
  - name: v1
    served: true
    storage: true
    schema:
      openAPIV3Schema:
        type: object
        properties:
          spec:
            type: object
            properties:
              message:
                type: string
          status:
            type: object
            properties:
              availableReplicas:
                type: integer
    subresources:
      status: {}
    additionalPrinterColumns:
    - name: Replicas
      type: string
      jsonPath: .status.availableReplicas
  names:
    kind: HelloType
    shortNames:
    - ht
    plural: hellotypes
    singular: hellotype

To generate your own code

  1. Install the following tools to your GOBIN directory.
      $ go install k8s.io/code-generator/cmd/client-gen@latest
      $ go install k8s.io/code-generator/cmd/applyconfiguration-gen@latest
      $ go install k8s.io/code-generator/cmd/conversion-gen@latest
      $ go install k8s.io/code-generator/cmd/deepcopy-gen@latest
      $ go install k8s.io/code-generator/cmd/defaulter-gen@latest
      $ go install k8s.io/code-generator/cmd/go-to-protobuf@latest
      $ go install k8s.io/code-generator/cmd/informer-gen@latest
      $ go install k8s.io/code-generator/cmd/prerelease-lifecycle-gen@latest
      $ go install k8s.io/code-generator/cmd/register-gen@latest
  2. Clone the kubernetes code-generator repository
    1. cd ~
    2. mkdir -p go/src/k8s.io
    3. cd go/src/k8s.io
    4. git clone https://github.com/kubernetes/code-generator.git
    5. cd code-generator
    6. git checkout v0.29.2
  3. Follow this guide to create the superman/demo repo with the golang code in the appropriate files:
    1. pkg/apis/foo/v1/doc.go
    2. pkg/apis/foo/v1/register.go
    3. pkg/apis/foo/v1/types.go
  4. In your demo repo
    1. go mod init
    2. git init
    3. git add .
    4. git commit -m "check in all demo files"
  5. Run the following to generate the k8s required code:
      /go/src/k8s.io/code-generator/generate-groups.sh all "github.com/superman/demo/pkg/client" "github.com/superman/demo/pkg/apis" foo:v1 --go-header-file ~/go/src/k8s.io/code-generator/examples/hack/boilerplate.go.txt
  6. Copy the generated code that was generated to github.com/ inside of your repo to the top level demo folder
    1. cp -R github.com/jacob-delgado/demo/pkg .
    2. rm -rf github.com
  7. go mod tidy
  8. git add .
  9. git commit -m "check in generated files"

Running this repository

  1. Install Skaffold.
  2. Install kind
  3. From your command line
      $ skaffold dev

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published