Skip to content

RedHatInsights/strimzi-client-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

strimzi-client-go

Strimzi client-go package for use with kubernetes controllers.

This is a work in progress and hopefully the generation of this package will be fully automated soon.

At the moment, the partially-automated process is:

  1. Download the strimzi CRD yaml

  2. Edit the openAPI schemas to remove any 'oneOf' statements, since the GoLang type generator we use does not handle those.

  3. Use crd-codegen to generate types from the CRD YAML.

  4. Edit the root type definitions in each file so that they implement the runtime.Object interfaces, add a "List" type for the root object, and add kubebuilder annotations. For example, the root "Kafka" object within Kafka.go will initially look like this:

    package v1beta2
    
    import "encoding/json"
    import "fmt"
    import "reflect"
    
    type Kafka struct {
        // The specification of the Kafka and ZooKeeper clusters, and Topic Operator.
        Spec *KafkaSpec `json:"spec,omitempty" yaml:"spec,omitempty" mapstructure:"spec,omitempty"`
    
        // The status of the Kafka and ZooKeeper clusters, and Topic Operator.
        Status *KafkaStatus `json:"status,omitempty" yaml:"status,omitempty" mapstructure:"status,omitempty"`
    }

    and it will need to be updated to look like this:

    package v1beta2
    
    import (
        "encoding/json"
        "fmt"
        "reflect"
    
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    
        apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
    )
    
    // +kubebuilder:object:root=true
    // +kubebuilder:subresource:status
    // Kafka
    type Kafka struct {
        metav1.TypeMeta   `json:",inline"`
        metav1.ObjectMeta `json:"metadata,omitempty"`
    
        // The specification of the Kafka and ZooKeeper clusters, and Topic Operator.
        Spec *KafkaSpec `json:"spec,omitempty" yaml:"spec,omitempty" mapstructure:"spec,omitempty"`
    
        // The status of the Kafka and ZooKeeper clusters, and Topic Operator.
        Status *KafkaStatus `json:"status,omitempty" yaml:"status,omitempty" mapstructure:"status,omitempty"`
    }
    
    // +kubebuilder:object:root=true
    // KafkaList contains a list of instances.
    type KafkaList struct {
        metav1.TypeMeta `json:",inline"`
        metav1.ListMeta `json:"metadata,omitempty"`
    
        // A list of Kafka objects.
        Items []Kafka `json:"items,omitempty"`
    }
  5. Some unstructured/"free-form" fields may be defined as type <name> map[string]interface{} and these must be changed to type apiextensions.JSON. The python script convert.py can be ran against each file to help with this.

  6. Convert int types to int32: sed -i 's/int `json/int32 `json'/g *

  7. Finally run controller-gen object paths=./... is run to generate DeepCopy implementations

About

Strimzi client-go package generated using crd-codegen

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •