Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend current ImageConfig to allow more values to images as well as … #505

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Changelog for Cass Operator, new PRs should update the `main / unreleased` secti
## unreleased

* [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] [#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
* [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
87 changes: 77 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,88 @@ 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, 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
Loading