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
…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
  • Loading branch information
burmanm committed Apr 12, 2024
1 parent faa4d28 commit e2df92b
Show file tree
Hide file tree
Showing 7 changed files with 321 additions and 56 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Changelog for Cass Operator, new PRs should update the `main / unreleased` secti

* [CHANGE] [#618](https://github.com/k8ssandra/cass-operator/issues/618) Update dependencies to support controller-runtime 0.17.2, modify required parts.
* [ENHANCEMENT] [#532](https://github.com/k8ssandra/cass-operator/issues/532) Instead of rejecting updates/creates with deprecated fields, return kubectl warnings.
* [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

## v1.19.1

Expand Down
82 changes: 73 additions & 9 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,6 +34,10 @@ type ImageConfig struct {

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

ImagePolicy
}

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

ImagePullSecret corev1.LocalObjectReference `json:"imagePullSecret,omitempty"`
Expand All @@ -52,24 +55,85 @@ type Images struct {

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

SystemLogger string `json:"system-logger"`

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 _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, 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"
SystemLoggerImageComponent string = "system-logger"
ConfigBuilderImageComponent string = "config-builder"
ClientImageComponent string = "k8ssandra-client"
)

type ImageComponents map[string]ImageComponent

type DefaultImages struct {
metav1.TypeMeta `json:",inline"`
ImageComponents
}

CassandraImageComponent ImageComponent `json:"cassandra,omitempty"`
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)
}

DSEImageComponent ImageComponent `json:"dse,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
59 changes: 54 additions & 5 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.

Loading

0 comments on commit e2df92b

Please sign in to comment.