Skip to content

Commit

Permalink
Fix bug for updating policy
Browse files Browse the repository at this point in the history
Fixes bug where policies were updated with no changes.

Pins container to version of app as well.
  • Loading branch information
hooksie1 committed May 26, 2022
1 parent f31f5d9 commit b808c5e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ func generate(cmd *cobra.Command, args []string) {
printKind(deployment.NewClusterRole())
printKind(deployment.NewClusterRolebinding(namespace))
fmt.Println(deployment.NewCRD())
printKind(deployment.NewDeployment(mService, namespace, "mutating", mSecret, port))
printKind(deployment.NewDeployment(vService, namespace, "validating", vSecret, port))
printKind(deployment.NewDeployment(mService, namespace, "mutating", mSecret, port, Version))
printKind(deployment.NewDeployment(vService, namespace, "validating", vSecret, port, Version))
printKind(deployment.NewService(mService, namespace, port))
printKind(deployment.NewService(vService, namespace, port))
printKind(deployment.CertAsSecret(mCert, mKey, mSecret, namespace))
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ require (
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/yashtewari/glob-intersection v0.1.0 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
golang.org/x/tools v0.1.10 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,7 @@ golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRu
golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
Expand Down Expand Up @@ -1504,6 +1505,8 @@ golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff/go.mod h1:YD9qOF0M9xpSpdWTBbzEl5e/RnCefISl8E5Noe10jFM=
golang.org/x/tools v0.1.10-0.20220218145154-897bd77cd717/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20=
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
14 changes: 12 additions & 2 deletions pkg/client/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,20 @@ func (c *Client) WatchResources() {
}
},
UpdateFunc: func(oldObj interface{}, newObj interface{}) {
if r, ok := newObj.(*v1alpha1.OpaPolicy); ok {
o, ok := oldObj.(*v1alpha1.OpaPolicy)
if !ok {
return
}
n, ok := newObj.(*v1alpha1.OpaPolicy)
if !ok {
return
}

// checking if spec matches. If not this is truly an update
if o.Spec.Policy != n.Spec.Policy {
m := v1alpha1.OpaMessage{
Method: "update",
OpaPolicy: *r,
OpaPolicy: *n,
}

c.Queue <- m
Expand Down
6 changes: 4 additions & 2 deletions pkg/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ type Deployment struct {
ServerType string
SecretName string
Port int
Version string
}

func NewDeployment(name, namespace, serverType, secretName string, port int) *appsv1.Deployment {
func NewDeployment(name, namespace, serverType, secretName string, port int, version string) *appsv1.Deployment {
dep := Deployment{
Name: name,
Namespace: namespace,
ServerType: serverType,
SecretName: secretName,
Port: port,
Version: version,
}

return dep.newDeployment()
Expand Down Expand Up @@ -61,7 +63,7 @@ func (d *Deployment) getTemplate() corev1.PodTemplateSpec {
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Image: "hooksie1/cmsnr:latest",
Image: fmt.Sprintf("hooksie1/cmsnr:%s", d.Version),
ImagePullPolicy: "Always",
Name: d.Name,
Args: []string{"server", "start", d.ServerType, fmt.Sprintf("-n=%s", d.Namespace)},
Expand Down

0 comments on commit b808c5e

Please sign in to comment.