Skip to content

Commit

Permalink
Merge pull request #255 from qclc/add-image-override
Browse files Browse the repository at this point in the history
feat(override): add image overrider
  • Loading branch information
mrlihanbo authored Nov 2, 2023
2 parents 3c336c6 + 91efa69 commit 2c3b898
Show file tree
Hide file tree
Showing 14 changed files with 2,080 additions and 21 deletions.
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ linters-settings:
{{ MAIN }}
CREDIT_BOILERPLATE: |-
The design of (the )?[a-zA-z0-9 ]*is inspired by [a-zA-z0-9 '-]*\. Kudos!
BOILERPLATE: "^({{ KUBERNETES_BOILERPLATE }}|{{ KUBEADMIRAL_BOILERPLATE }}|{{ CREDIT_BOILERPLATE }})$"
LIFTED_BOILERPLATE: |-
This file is lifted from [a-zA-z0-9 '/':'.]*
BOILERPLATE: "^({{ KUBERNETES_BOILERPLATE }}|{{ KUBEADMIRAL_BOILERPLATE }}|{{ CREDIT_BOILERPLATE }}|{{ LIFTED_BOILERPLATE }})$"
template: "{{ BOILERPLATE }}"
forbidigo:
# Forbid the following identifiers (list of regexp).
Expand Down
42 changes: 42 additions & 0 deletions config/crds/core.kubeadmiral.io_clusteroverridepolicies.yaml

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

42 changes: 42 additions & 0 deletions config/crds/core.kubeadmiral.io_overridepolicies.yaml

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

2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.19

require (
github.com/davecgh/go-spew v1.1.1
github.com/distribution/reference v0.5.0
github.com/evanphx/json-patch v5.6.0+incompatible
github.com/evanphx/json-patch/v5 v5.6.0
github.com/go-logr/logr v1.2.4
Expand Down Expand Up @@ -56,6 +57,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/emicklei/go-restful/v3 v3.9.0 h1:XwGDlfxEnQZzuopoqxwSEllNcCOM9DhhFyhFIIGKwxE=
github.com/emicklei/go-restful/v3 v3.9.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
Expand Down Expand Up @@ -231,6 +233,8 @@ github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU
github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM=
github.com/onsi/gomega v1.27.8 h1:gegWiwZjBsf2DgiSbf5hpokZ98JVDMcWkUiigk6/KXc=
github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJKFnNQ=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM=
github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
43 changes: 43 additions & 0 deletions pkg/apis/core/v1alpha1/types_overridepolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,55 @@ type TargetClusters struct {
ClusterAffinity []ClusterSelectorTerm `json:"clusterAffinity,omitempty"`
}

// Overriders contains a list of override patches.
// The order in which the override patches take effect is:
// - Image
// - JsonPatch
type Overriders struct {
// Image specifies the overriders that applies to the image.
// +optional
Image []ImageOverrider `json:"image,omitempty"`
// JsonPatch specifies overriders in a syntax similar to RFC6902 JSON Patch.
// +optional
JsonPatch []JsonPatchOverrider `json:"jsonpatch,omitempty"`
}

type ImageOverrider struct {
// ContainerNames are ignored when ImagePath is set.
// If empty, the image override rule applies to all containers.
// Otherwise, this override targets the specified container(s) or init container(s) in the pod template.
// +optional
ContainerNames []string `json:"containerNames,omitempty"`

// ImagePath indicates the image path to target.
// For Example: /spec/template/spec/containers/0/image
//
// If empty, the system will automatically resolve the image path if the resource type is
// Pod, CronJob, Deployment, StatefulSet, DaemonSet or Job.
// +optional
ImagePath string `json:"imagePath,omitempty"`

// Operations are the specific operations to be performed on ContainerNames or ImagePath.
Operations []Operation `json:"operations"`
}

type Operation struct {
// ImageComponent is the part of the image to override.
// +kubebuilder:validation:Enum=Registry;Repository;Tag;Digest
ImageComponent string `json:"imageComponent"`

// Operator specifies the operation.
// If omitted, defaults to "replace".
// For "add" operation, if the ImageComponent already has a value, it behaves as a "replace" action.
// +kubebuilder:validation:Enum=add;remove;replace
// +optional
Operator string `json:"operator,omitempty"`

// Value is the value required by the operation.
// +optional
Value string `json:"value,omitempty"`
}

type JsonPatchOverrider struct {
// Operator specifies the operation.
// If omitted, defaults to "replace".
Expand Down
49 changes: 49 additions & 0 deletions pkg/apis/core/v1alpha1/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 2c3b898

Please sign in to comment.