Commit 35101674 authored by André Carvalho's avatar André Carvalho

updates nginx spec in deployment annotation

parent ba7b87aa
......@@ -113,6 +113,9 @@ func reconcileDeployment(ctx context.Context, nginx *v1alpha1.Nginx, logger *log
}
currDeploy.Spec = newDeploy.Spec
if err := k8s.SetNginxSpec(&currDeploy.ObjectMeta, nginx.Spec); err != nil {
return fmt.Errorf("failed to set nginx spec into object meta: %v", err)
}
if err := sdk.Update(currDeploy); err != nil {
return fmt.Errorf("failed to update deployment: %v", err)
......
......@@ -94,13 +94,9 @@ func NewDeployment(n *v1alpha1.Nginx) (*appv1.Deployment, error) {
setupTLS(n.Spec.TLSSecret, &deployment)
// This is done on the last step because n.Spec may have mutated during these methods
origSpec, err := json.Marshal(n.Spec)
if err != nil {
if err := SetNginxSpec(&deployment.ObjectMeta, n.Spec); err != nil {
return nil, err
}
deployment.Annotations = map[string]string{
generatedFromAnnotation: string(origSpec),
}
return &deployment, nil
}
......@@ -169,6 +165,19 @@ func ExtractNginxSpec(o metav1.ObjectMeta) (v1alpha1.NginxSpec, error) {
return spec, nil
}
// SetNginxSpec sets the nginx spec into the object annotation to be later extracted
func SetNginxSpec(o *metav1.ObjectMeta, spec v1alpha1.NginxSpec) error {
if o.Annotations == nil {
o.Annotations = make(map[string]string)
}
origSpec, err := json.Marshal(spec)
if err != nil {
return err
}
o.Annotations[generatedFromAnnotation] = string(origSpec)
return nil
}
func setupConfig(conf *v1alpha1.ConfigRef, dep *appv1.Deployment) {
if conf == nil {
return
......
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