Skip to content

Commit

Permalink
Extend current ImageConfig to allow more values to images as well as … (
Browse files Browse the repository at this point in the history
#505)

* Extend current ImageConfig to allow more values to images as well as additional configuration options for each image type

Add modified PullPolicy to containers

Add ability to restrict pullSecrets added per pod

Make internal imageConfig to be non-pointer to allow easier usage in tests

Make some pointer accesses safer

* Add new field (imageNamespace) and tests for it

* Add support for namespace overrides in image pulling

* Add HCD version override test

* Fix UnmarshalJSON to remove hcd field before doing double unmarshalling
  • Loading branch information
burmanm authored Nov 25, 2024
1 parent 3f699c5 commit bf4a6a4
Show file tree
Hide file tree
Showing 10 changed files with 469 additions and 81 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Changelog for Cass Operator, new PRs should update the `main / unreleased` secti
* [CHANGE] [#720](https://github.com/k8ssandra/cass-operator/issues/720) Always use ObjectMeta.Name for the PodDisruptionBudget resource name, not the DatacenterName
* [FEATURE] [#651](https://github.com/k8ssandra/cass-operator/issues/651) Add tsreload task for DSE deployments and ability to check if sync operation is available on the mgmt-api side
* [ENHANCEMENT] [#722](https://github.com/k8ssandra/cass-operator/issues/722) Add back the ability to track cleanup task before marking scale up as done. This is controlled by an annotation cassandra.datastax.com/track-cleanup-tasks
* [ENHANCEMENT] [#532](https://github.com/k8ssandra/k8ssandra-operator/issues/532) Extend ImageConfig type to allow additional parameters for k8ssandra-operator requirements. These include per-image PullPolicy / PullSecrets as well as additional image. Also add ability to override a single HCD version image.
* [ENHANCEMENT] [#636](https://github.com/k8ssandra/cass-operator/issues/636) Add support for new field in ImageConfig, imageNamespace. This will allow to override namespace of all images when using private registries. Setting it to empty will remove the namespace entirely.
* [BUGFIX] [#705](https://github.com/k8ssandra/cass-operator/issues/705) Ensure ConfigSecret has annotations map before trying to set a value

## v1.22.4
Expand Down
88 changes: 78 additions & 10 deletions apis/config/v1beta1/imageconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ limitations under the License.
package v1beta1

import (
"encoding/json"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

//+kubebuilder:object:root=true
//+kubebuilder:subresource:images

Expand All @@ -35,11 +34,17 @@ type ImageConfig struct {

DefaultImages *DefaultImages `json:"defaults,omitempty"`

ImagePolicy
}

type ImagePolicy struct {
ImageRegistry string `json:"imageRegistry,omitempty"`

ImagePullSecret corev1.LocalObjectReference `json:"imagePullSecret,omitempty"`

ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"`

ImageNamespace *string `json:"imageNamespace,omitempty"`
}

//+kubebuilder:object:root=true
Expand All @@ -52,26 +57,89 @@ type Images struct {

DSEVersions map[string]string `json:"dse,omitempty"`

SystemLogger string `json:"system-logger"`
HCDVersions map[string]string `json:"hcd,omitempty"`

ConfigBuilder string `json:"config-builder"`
SystemLogger string `json:"system-logger,omitempty"`

Client string `json:"k8ssandra-client,omitempty"`

ConfigBuilder string `json:"config-builder,omitempty"`

Others map[string]string `json:",inline,omitempty"`
}

type DefaultImages struct {
metav1.TypeMeta `json:",inline"`
type _Images Images

func (i *Images) UnmarshalJSON(b []byte) error {
var imagesTemp _Images
if err := json.Unmarshal(b, &imagesTemp); err != nil {
return err
}
*i = Images(imagesTemp)

var otherFields map[string]interface{}
if err := json.Unmarshal(b, &otherFields); err != nil {
return err
}

delete(otherFields, CassandraImageComponent)
delete(otherFields, DSEImageComponent)
delete(otherFields, HCDImageComponent)
delete(otherFields, SystemLoggerImageComponent)
delete(otherFields, ConfigBuilderImageComponent)
delete(otherFields, ClientImageComponent)

others := make(map[string]string, len(otherFields))
for k, v := range otherFields {
others[k] = v.(string)
}

i.Others = others
return nil
}

const (
CassandraImageComponent string = "cassandra"
DSEImageComponent string = "dse"
HCDImageComponent string = "hcd"
SystemLoggerImageComponent string = "system-logger"
ConfigBuilderImageComponent string = "config-builder"
ClientImageComponent string = "k8ssandra-client"
)

CassandraImageComponent ImageComponent `json:"cassandra,omitempty"`
type ImageComponents map[string]ImageComponent

DSEImageComponent ImageComponent `json:"dse,omitempty"`
type DefaultImages struct {
ImageComponents
}

func (d *DefaultImages) MarshalJSON() ([]byte, error) {
// This shouldn't be required, just like it's not with ImagePolicy, but this is Go..
return json.Marshal(d.ImageComponents)
}

HCDImageComponent ImageComponent `json:"hcd,omitempty"`
func (d *DefaultImages) UnmarshalJSON(b []byte) error {
d.ImageComponents = make(map[string]ImageComponent)
var input map[string]json.RawMessage
if err := json.Unmarshal(b, &input); err != nil {
return err
}

for k, v := range input {
var component ImageComponent
if err := json.Unmarshal(v, &component); err != nil {
return err
}
d.ImageComponents[k] = component
}

return nil
}

type ImageComponent struct {
Repository string `json:"repository,omitempty"`
Suffix string `json:"suffix,omitempty"`
ImagePolicy
}

func init() {
Expand Down
72 changes: 66 additions & 6 deletions apis/config/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/manager/image_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ images:
# dse:
# "6.8.999": "datastax/dse-server-prototype:latest"
# imageRegistry: "localhost:5000"
# imageNamespace: "internal"
# imagePullPolicy: Always
# imagePullSecret:
# name: my-secret-pull-registry
Expand Down
Loading

0 comments on commit bf4a6a4

Please sign in to comment.