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

Refactor reconciler #120

Merged
merged 23 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ lieutenant-operator
cmd/manager/__debug_bin

tempgopath

.cache/
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [unreleased] - 2020-10-22
### Changed
- Redesigned reconcile handling ([#120])
- GitRepo objects now fetch their information instead of them receiving from other controllers ([#120])
### Fixed
- Lot's of race conditions and smaller bugs ([#120])

## [v0.4.0] - 2020-10-20
### Added
- Configurable revisions for git repositories ([#116])
Expand Down Expand Up @@ -113,3 +121,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#104]: https://github.com/projectsyn/lieutenant-operator/pull/104
[#110]: https://github.com/projectsyn/lieutenant-operator/pull/110
[#116]: https://github.com/projectsyn/lieutenant-operator/pull/116
[#120]: https://github.com/projectsyn/lieutenant-operator/pull/120
4 changes: 2 additions & 2 deletions examples/gitrepo-secret.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
stringData:
endpoint: http://192.168.5.42:8080
token: vY3gHvPs82NvYK8dKAGw
endpoint: http://192.168.5.195:8080
token: oqepRZZtm2QymfTXErHX
kind: Secret
metadata:
name: example-secret
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ github.com/coreos/etcd v3.3.17+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-oidc v2.1.0+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
Expand Down Expand Up @@ -1275,6 +1276,7 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20190905181640-827449938966/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
helm.sh/helm/v3 v3.1.0/go.mod h1:WYsFJuMASa/4XUqLyv54s0U/f3mlAaRErGmyy4z921g=
helm.sh/helm/v3 v3.1.2 h1:VpNzaNv2DX4aRnOCcV7v5Of+XT2SZrJ8iOQ25AGKOos=
Expand Down
26 changes: 26 additions & 0 deletions pkg/apis/syn/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,29 @@ type ClusterList struct {
func init() {
SchemeBuilder.Register(&Cluster{}, &ClusterList{})
}

// GetGitTemplate returns the git repository template
func (c *Cluster) GetGitTemplate() *GitRepoTemplate {
return c.Spec.GitRepoTemplate
}

// GetTenantRef returns the tenant of this CR
func (c *Cluster) GetTenantRef() corev1.LocalObjectReference {
return c.Spec.TenantRef
}

// GetDeletionPolicy returns the object's deletion policy
func (c *Cluster) GetDeletionPolicy() DeletionPolicy {
return c.Spec.DeletionPolicy
}

// GetDisplayName returns the display name of the object
func (c *Cluster) GetDisplayName() string {
return c.Spec.DisplayName
}

// SetGitRepoURLAndHostKeys
func (c *Cluster) SetGitRepoURLAndHostKeys(URL, hostKeys string) {
c.Spec.GitRepoURL = URL
c.Spec.GitHostKeys = hostKeys
}
25 changes: 25 additions & 0 deletions pkg/apis/syn/v1alpha1/gitrepo_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,28 @@ type GitRepoList struct {
func init() {
SchemeBuilder.Register(&GitRepo{}, &GitRepoList{})
}

// GetGitTemplate returns the git repository template
func (g *GitRepo) GetGitTemplate() *GitRepoTemplate {
return &g.Spec.GitRepoTemplate
}

// GetTenantRef returns the tenant of this CR
func (g *GitRepo) GetTenantRef() corev1.LocalObjectReference {
return g.Spec.TenantRef
}

// GetDeletionPolicy returns the object's deletion policy
func (g *GitRepo) GetDeletionPolicy() DeletionPolicy {
return g.Spec.DeletionPolicy
}

// GetDisplayName returns the display name of the object
func (g *GitRepo) GetDisplayName() string {
return g.Spec.DisplayName
}

// SetGitRepoURLAndHostKeys is currenlty a noop for gitrepo
func (g *GitRepo) SetGitRepoURLAndHostKeys(URL, hostKeys string) {
//NOOP
}
29 changes: 29 additions & 0 deletions pkg/apis/syn/v1alpha1/tenant_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -62,3 +63,31 @@ type TenantList struct {
func init() {
SchemeBuilder.Register(&Tenant{}, &TenantList{})
}

// GetGitTemplate returns the git repository template
func (t *Tenant) GetGitTemplate() *GitRepoTemplate {
if t.Spec.GitRepoTemplate == nil {
t.Spec.GitRepoTemplate = &GitRepoTemplate{}
}
return t.Spec.GitRepoTemplate
}

// GetTenantRef returns the tenant of this CR
func (t *Tenant) GetTenantRef() corev1.LocalObjectReference {
return corev1.LocalObjectReference{Name: t.GetName()}
}

// GetDeletionPolicy returns the object's deletion policy
func (t *Tenant) GetDeletionPolicy() DeletionPolicy {
return t.Spec.DeletionPolicy
}

// GetDisplayName returns the display name of the object
func (t *Tenant) GetDisplayName() string {
return t.Spec.DisplayName
}

// SetGitRepoURLAndHostKeys will only set the URL for the tenant
func (t *Tenant) SetGitRepoURLAndHostKeys(URL, hostKeys string) {
t.Spec.GitRepoURL = URL
}
24 changes: 24 additions & 0 deletions pkg/collection/values.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package collection

import (
corev1 "k8s.io/api/core/v1"
)

const (
// DeleteProtectionAnnotation defines the delete protection annotation name
DeleteProtectionAnnotation = "syn.tools/protected-delete"
)

type SecretSortList corev1.SecretList

func (s SecretSortList) Len() int { return len(s.Items) }
func (s SecretSortList) Swap(i, j int) { s.Items[i], s.Items[j] = s.Items[j], s.Items[i] }

func (s SecretSortList) Less(i, j int) bool {

if s.Items[i].CreationTimestamp.Equal(&s.Items[j].CreationTimestamp) {
return s.Items[i].Name < s.Items[j].Name
}

return s.Items[i].CreationTimestamp.Before(&s.Items[j].CreationTimestamp)
}
3 changes: 1 addition & 2 deletions pkg/controller/cluster/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
if err != nil {
return err
}

return c.Watch(&source.Kind{Type: &synv1alpha1.GitRepo{}}, &handler.EnqueueRequestForOwner{
srueg marked this conversation as resolved.
Show resolved Hide resolved
IsController: true,
OwnerType: &synv1alpha1.Cluster{},
OwnerType: &synv1alpha1.Tenant{},
})

}
Expand Down
Loading