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

feat: implement AssignImage mutator #2429

Merged
merged 34 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c06edf7
Implement AssignImage mutator
davis-haba Dec 6, 2022
acab9fe
fix tests
davis-haba Dec 6, 2022
cc6b0ad
fix controller gen setup
davis-haba Dec 6, 2022
e644184
fix helm manifest generation
davis-haba Dec 7, 2022
f20bf4f
WIP assignimage byPod status
davis-haba Dec 7, 2022
f02daed
mutator pod status working for assignimage
davis-haba Dec 7, 2022
6eada2f
e2e test assignimage mutator deleted
davis-haba Dec 7, 2022
f586335
old kubectl run
davis-haba Dec 7, 2022
a3e64d1
address comments. domain must have '.' unless localhost
davis-haba Dec 8, 2022
2eac13b
appease linter
davis-haba Dec 8, 2022
b9499ab
fix gator tests
davis-haba Dec 8, 2022
b5521ff
add test domain ending in colon still converges
davis-haba Dec 8, 2022
7bb472f
docs for assignimage
davis-haba Dec 8, 2022
fc2b112
remove newline
davis-haba Dec 8, 2022
fa11b39
address comments
davis-haba Dec 14, 2022
8cf83ab
appease linter
davis-haba Dec 14, 2022
f6baca6
cleanup dead code branch
davis-haba Dec 14, 2022
4e88c2c
validateDomain to use splitDomain
davis-haba Dec 15, 2022
adbe835
future-proof validateImageParts. Add custom error types.
davis-haba Dec 22, 2022
f553ff2
fix readiness tracker test
davis-haba Dec 22, 2022
52fa795
make manifests
davis-haba Dec 22, 2022
e4baaae
validate that splitting a valid tag never returns a path
davis-haba Dec 30, 2022
9b38667
Merge branch 'master' into docker-image-mutator
davis-haba Jan 3, 2023
9102ee9
degenerate cases for unit tests. do not expose regex on image compone…
davis-haba Jan 10, 2023
a97be6a
test missing image field. update error copy.
davis-haba Jan 11, 2023
88df8e5
tag error copy
davis-haba Jan 11, 2023
69d3930
Merge branch 'master' into docker-image-mutator
sozercan Jan 20, 2023
81095a6
Merge branch 'master' into docker-image-mutator
davis-haba Jan 21, 2023
50d8f16
Update pkg/expansion/system_test.go
davis-haba Jan 21, 2023
82e78eb
Update pkg/mutation/mutators/assignimage/assignimage_mutator.go
davis-haba Jan 21, 2023
c269326
Merge branch 'master' into docker-image-mutator
davis-haba Jan 21, 2023
09389e3
errors.As instead of type casting in unit tests
davis-haba Jan 21, 2023
d2caf9f
fix error type checking
davis-haba Jan 21, 2023
2012f39
Merge branch 'master' into docker-image-mutator
sozercan Jan 24, 2023
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
90 changes: 90 additions & 0 deletions apis/mutations/unversioned/assignimage_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package unversioned

import (
"github.com/open-policy-agent/gatekeeper/apis/status/v1beta1"
"github.com/open-policy-agent/gatekeeper/pkg/mutation/match"
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.

// AssignImageSpec defines the desired state of AssignImage.
type AssignImageSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// ApplyTo lists the specific groups, versions and kinds a mutation will be applied to.
// This is necessary because every mutation implies part of an object schema and object
// schemas are associated with specific GVKs.
ApplyTo []match.ApplyTo `json:"applyTo,omitempty"`

// Match allows the user to limit which resources get mutated.
// Individual match criteria are AND-ed together. An undefined
// match criteria matches everything.
Match match.Match `json:"match,omitempty"`

// Location describes the path to be mutated, for example: `spec.containers[name: main].image`.
Location string `json:"location,omitempty"`

// Parameters define the behavior of the mutator.
Parameters AssignImageParameters `json:"parameters,omitempty"`
}

type AssignImageParameters struct {
PathTests []PathTest `json:"pathTests,omitempty"`

// AssignDomain sets the domain component on an image string. The trailing
// slash should not be included.
AssignDomain string `json:"assignDomain,omitempty"`

// AssignPath sets the domain component on an image string.
AssignPath string `json:"assignPath,omitempty"`

// AssignImage sets the image component on an image string. It must start
// with a `:` or `@`.
AssignTag string `json:"assignTag,omitempty"`
}

// AssignImageStatus defines the observed state of AssignImage.
type AssignImageStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

ByPod []v1beta1.MutatorPodStatusStatus `json:"byPod,omitempty"`
}

// +kubebuilder:object:root=true

// AssignImage is the Schema for the assign API.
type AssignImage struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec AssignImageSpec `json:"spec,omitempty"`
Status AssignImageStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// AssignImageList contains a list of AssignImage.
type AssignImageList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []AssignImage `json:"items"`
}
125 changes: 125 additions & 0 deletions apis/mutations/unversioned/zz_generated.deepcopy.go

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

97 changes: 97 additions & 0 deletions apis/mutations/v1alpha1/assignimage_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"github.com/open-policy-agent/gatekeeper/apis/status/v1beta1"
"github.com/open-policy-agent/gatekeeper/pkg/mutation/match"
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.

// AssignImageSpec defines the desired state of AssignImage.
type AssignImageSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// ApplyTo lists the specific groups, versions and kinds a mutation will be applied to.
// This is necessary because every mutation implies part of an object schema and object
// schemas are associated with specific GVKs.
ApplyTo []match.ApplyTo `json:"applyTo,omitempty"`

// Match allows the user to limit which resources get mutated.
// Individual match criteria are AND-ed together. An undefined
// match criteria matches everything.
Match match.Match `json:"match,omitempty"`

// Location describes the path to be mutated, for example: `spec.containers[name: main].image`.
Location string `json:"location,omitempty"`

// Parameters define the behavior of the mutator.
Parameters AssignImageParameters `json:"parameters,omitempty"`
}

type AssignImageParameters struct {
PathTests []PathTest `json:"pathTests,omitempty"`

// AssignDomain sets the domain component on an image string. The trailing
// slash should not be included.
AssignDomain string `json:"assignDomain,omitempty"`

// AssignPath sets the domain component on an image string.
AssignPath string `json:"assignPath,omitempty"`

// AssignImage sets the image component on an image string. It must start
// with a `:` or `@`.
AssignTag string `json:"assignTag,omitempty"`
}

// AssignImageStatus defines the observed state of AssignImage.
type AssignImageStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

ByPod []v1beta1.MutatorPodStatusStatus `json:"byPod,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:resource:path="assignimage"
// +kubebuilder:resource:scope="Cluster"
// +kubebuilder:subresource:status

// AssignImage is the Schema for the assignimage API.
type AssignImage struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec AssignImageSpec `json:"spec,omitempty"`
Status AssignImageStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// AssignImageList contains a list of AssignImage.
type AssignImageList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []AssignImage `json:"items"`
}

func init() {
SchemeBuilder.Register(&AssignImage{}, &AssignImageList{})
}
Loading