Documentation ¶
Index ¶
- Constants
- func CreateOrUpdate(ctx context.Context, client ctrlclient.Client, obj ctrlclient.Object) (mutation bool, err error)
- func GetObjectGVK(schema *runtime.Scheme, obj ctrlclient.Object) (*schema.GroupVersionKind, error)
- type Client
- func (c *Client) CreateOrUpdate(ctx context.Context, obj ctrlclient.Object) (mutation bool, err error)
- func (c *Client) Get(ctx context.Context, obj ctrlclient.Object) error
- func (c *Client) GetCtrlClient() ctrlclient.Client
- func (c *Client) GetCtrlScheme() *runtime.Scheme
- func (c *Client) GetOwnerName() string
- func (c *Client) GetOwnerNamespace() string
- func (c *Client) GetOwnerReference() ctrlclient.Object
- func (c *Client) SetOwnerReference(obj ctrlclient.Object, gvk *schema.GroupVersionKind) error
- type DataBaseType
- type DatabaseConfiguration
- func (d *DatabaseConfiguration) GetCredential(name string) (*DatabaseCredential, error)
- func (d *DatabaseConfiguration) GetDatabaseParams() (*DatabaseParams, error)
- func (d *DatabaseConfiguration) GetJDBCUrl() (string, error)
- func (d *DatabaseConfiguration) GetNamespace() string
- func (d *DatabaseConfiguration) GetRefDatabase(ctx context.Context) (dbv1alpha1.Database, error)
- func (d *DatabaseConfiguration) GetRefDatabaseConnection(name string) (dbv1alpha1.DatabaseConnection, error)
- func (d *DatabaseConfiguration) GetRefDatabaseName() string
- type DatabaseCredential
- type DatabaseParams
Constants ¶
const ( DbUsernameName = "USERNAME" DbPasswordName = "PASSWORD" )
Variables ¶
This section is empty.
Functions ¶
func CreateOrUpdate ¶ added in v0.8.1
func CreateOrUpdate(ctx context.Context, client ctrlclient.Client, obj ctrlclient.Object) (mutation bool, err error)
CreateOrUpdate creates or updates an object in the Kubernetes cluster. It takes the following parameters: - ctx: The context.Context object for the operation. - obj: The object to be created or updated. - client: The Kubernetes client used to interact with the cluster. It returns a boolean value indicating whether the object was mutated and an error, if any. The function first checks if the object exists in the cluster. If it doesn't, a new object is created. If the object already exists, it calculates the patch to match the existing object and the desired object. If the patch is not empty, it updates the object with the patch. The function also preserves certain fields and annotations during the update process. If any error occurs during the creation or update, it is returned along with the mutation status. Parameters:
- ctx: The context for the operation.
- client: The Kubernetes client used to interact with the cluster.
- obj: The object to create or update.
Returns:
- mutation: A boolean indicating whether a mutation occurred.
- error: An error if the operation fails, otherwise nil.
func GetObjectGVK ¶
func GetObjectGVK(schema *runtime.Scheme, obj ctrlclient.Object) (*schema.GroupVersionKind, error)
GetObjectGVK returns the GroupVersionKind (GVK) of the provided object. It retrieves the GVK by using the scheme.Scheme.ObjectKinds function. If the GVK is not found or there is an error retrieving it, an error is returned.
Types ¶
type Client ¶
type Client struct { Client ctrlclient.Client OwnerReference ctrlclient.Object }
func NewClient ¶ added in v0.8.0
func NewClient(client ctrlclient.Client, ownerReference ctrlclient.Object) *Client
NewClient returns a new instance of the Client struct. It accepts a control client `client` and an owner reference `ownerReference`.
func (*Client) CreateOrUpdate ¶
func (c *Client) CreateOrUpdate(ctx context.Context, obj ctrlclient.Object) (mutation bool, err error)
CreateOrUpdate creates or updates an object in the Kubernetes cluster. It takes the following parameters: - ctx: The context.Context object for the operation. - obj: The object to be created or updated. - client: The Kubernetes client used to interact with the cluster. It returns a boolean value indicating whether the object was mutated and an error, if any. The function first checks if the object exists in the cluster. If it doesn't, a new object is created. If the object already exists, it calculates the patch to match the existing object and the desired object. If the patch is not empty, it updates the object with the patch. The function also preserves certain fields and annotations during the update process. If any error occurs during the creation or update, it is returned along with the mutation status. Parameters:
- ctx: The context for the operation.
- obj: The object to create or update.
Returns:
- mutation: A boolean indicating whether a mutation occurred.
- error: An error if the operation fails, otherwise nil.
func (*Client) Get ¶
Get retrieves the object specified by the given `obj` from the Kubernetes cluster. It accepts a context `ctx` for cancellation and a `obj` of type `ctrlclient.Object` that represents the object to be retrieved. If the `obj` does not have a namespace specified, it uses the owner's namespace. It returns an error if the retrieval fails, along with additional information about the resource. Parameters:
- ctx: The context for the operation.
- obj: The object to retrieve.
Returns:
- error: An error if the operation fails, otherwise nil.
Example:
client := &Client{} // Get a service in the same namespace as the owner object svcInOwnerNamespace := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{Name: "my-svc"}, } if err := client.Get(context.Background(), svcInOwnerNamespace); err != nil { return } // Get a service in another namespace svcInAnotherNamespace := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{Name: "my-svc", Namespace: "another-ns"}, } if err := client.Get(context.Background(), svcInAnotherNamespace); err != nil { return }
func (*Client) GetCtrlClient ¶
func (c *Client) GetCtrlClient() ctrlclient.Client
GetCtrlClient returns the control client associated with the client.
func (*Client) GetCtrlScheme ¶
GetCtrlScheme returns the control scheme used by the client.
func (*Client) GetOwnerName ¶
GetOwnerName returns the name of the owner reference.
func (*Client) GetOwnerNamespace ¶
GetOwnerNamespace returns the namespace of the owner reference.
func (*Client) GetOwnerReference ¶
func (c *Client) GetOwnerReference() ctrlclient.Object
GetOwnerReference returns the owner reference of the client.
func (*Client) SetOwnerReference ¶
func (c *Client) SetOwnerReference(obj ctrlclient.Object, gvk *schema.GroupVersionKind) error
SetOwnerReference sets the owner reference for the given object. If the object doesn't have a namespace, it skips setting the owner reference and returns nil. If the client's OwnerReference is nil, it skips setting the owner reference and returns nil. Otherwise, it sets the owner reference using the ctrl.SetControllerReference function. It logs an error if setting the owner reference fails. Finally, it logs a message indicating that the owner reference has been set for the object. Parameters:
- obj: The object for which to set the owner reference.
- gvk: The GroupVersionKind of the object.
Returns:
- error: An error if setting the owner reference fails, otherwise nil.
type DataBaseType ¶
type DataBaseType string
const ( Postgres DataBaseType = "postgresql" Mysql DataBaseType = "mysql" Derby DataBaseType = "derby" Unknown DataBaseType = "unknown" )
type DatabaseConfiguration ¶
type DatabaseConfiguration struct { DbReference *string DbInline *DatabaseParams Namespace string Context context.Context Client *Client }
DatabaseConfiguration is a struct that holds the configuration for a database. example1:
dbConfig := &DatabaseConfiguration{DbReference: &ref, Context: ctx, Client: client} dbConfig.GetDatabaseParams() dbConfig.GetURI()
example2:
func (*DatabaseConfiguration) GetCredential ¶
func (d *DatabaseConfiguration) GetCredential(name string) (*DatabaseCredential, error)
func (*DatabaseConfiguration) GetDatabaseParams ¶
func (d *DatabaseConfiguration) GetDatabaseParams() (*DatabaseParams, error)
func (*DatabaseConfiguration) GetJDBCUrl ¶
func (d *DatabaseConfiguration) GetJDBCUrl() (string, error)
GetJDBCUrl returns the JDBC URL for the database. Supported: - Postgres - Mysql - Derby
- `derby:dbName;create=true`, the dbName is a file path.
func (*DatabaseConfiguration) GetNamespace ¶
func (d *DatabaseConfiguration) GetNamespace() string
func (*DatabaseConfiguration) GetRefDatabase ¶
func (d *DatabaseConfiguration) GetRefDatabase(ctx context.Context) (dbv1alpha1.Database, error)
func (*DatabaseConfiguration) GetRefDatabaseConnection ¶
func (d *DatabaseConfiguration) GetRefDatabaseConnection(name string) (dbv1alpha1.DatabaseConnection, error)
func (*DatabaseConfiguration) GetRefDatabaseName ¶
func (d *DatabaseConfiguration) GetRefDatabaseName() string
type DatabaseCredential ¶
type DatabaseParams ¶
type DatabaseParams struct { DbType DataBaseType Driver string Username string Password string Host string Port int32 DbName string }