Commit 3d36cb3d authored by Claudio Gonçalves's avatar Claudio Gonçalves Committed by Claudio Netto

controller: simplfy the file items to be a map

parent 78f4e987
......@@ -127,17 +127,6 @@ type TLSSecret struct {
CertificatePath string
}
// FileItem is a mapping from a key (in a ConfigMap object) to a final location
// on the container's filesystem.
type FileItem struct {
// Key refereces to a key field of a ConfigMap.
Key string
// Path is the final location where the file should be stored inside the
// nginx container.
Path string `json:"path"`
}
// FilesRef is a reference to arbitrary files stored into a ConfigMap in the
// cluster.
type FilesRef struct {
......@@ -145,14 +134,10 @@ type FilesRef struct {
// the files.
Name string `json:"name"`
// Files represents a file as a key-value on ConfigMap object. When it's not
// set, each entry on ConfigMap will be mounted as usually (key is the
// filename and the value as its content).
// Files maps the files from a ConfigMap to their locations into a container
// filesystem.
// Files maps each key entry from the ConfigMap to its relative location on
// the nginx filesystem.
// +optional
Files []FileItem `json:"files,omitempty"`
Files map[string]string `json:"files,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
......
......@@ -25,29 +25,15 @@ func (in *ConfigRef) DeepCopy() *ConfigRef {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *FileItem) DeepCopyInto(out *FileItem) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FileItem.
func (in *FileItem) DeepCopy() *FileItem {
if in == nil {
return nil
}
out := new(FileItem)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *FilesRef) DeepCopyInto(out *FilesRef) {
*out = *in
if in.Files != nil {
in, out := &in.Files, &out.Files
*out = make([]FileItem, len(*in))
copy(*out, *in)
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
return
}
......
......@@ -311,12 +311,12 @@ func setupExtraFiles(fRef *v1alpha1.FilesRef, dep *appv1.Deployment) {
Name: volumeMountName,
MountPath: extraFilesMountPath,
})
items := make([]corev1.KeyToPath, len(fRef.Files))
for i, item := range fRef.Files {
items[i] = corev1.KeyToPath{
Key: item.Key,
Path: item.Path,
}
var items []corev1.KeyToPath
for key, path := range fRef.Files {
items = append(items, corev1.KeyToPath{
Key: key,
Path: path,
})
}
dep.Spec.Template.Spec.Volumes = append(dep.Spec.Template.Spec.Volumes, corev1.Volume{
Name: volumeMountName,
......
......@@ -373,19 +373,10 @@ func Test_NewDeployment(t *testing.T) {
nginxFn: func(n v1alpha1.Nginx) v1alpha1.Nginx {
n.Spec.ExtraFiles = &v1alpha1.FilesRef{
Name: "my-extra-files-in-configmap",
Files: []v1alpha1.FileItem{
{
Key: "www_index.html",
Path: "www/index.html",
},
{
Key: "another-nginx.cnf",
Path: "another-nginx.cnf",
},
{
Key: "waf_sqli-rules.cnf",
Path: "waf/sqli-rules.cnf",
},
Files: map[string]string{
"www_index.html": "www/index.html",
"another-nginx.cnf": "another-nginx.cnf",
"waf_sqli-rules.cnf": "waf/sqli-rules.cnf",
},
}
return n
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment