Commit e6b0cea3 authored by Geoff Simmons's avatar Geoff Simmons

Move the Status type into pkg/k8s, unclutters the packages a bit.

parent d8a4a4ed
......@@ -36,7 +36,6 @@ check: build
golint ./pkg/crt/...
golint ./pkg/pem/...
golint ./pkg/rest/...
golint ./pkg/update/...
golint ./pkg/k8s/...
go test -v ./pkg/crt/... ./pkg/pem/... ./pkg/rest/...
......
......@@ -26,12 +26,7 @@
* SUCH DAMAGE.
*/
// Package update defines the Status type, which classifies the result
// of a synchronization operation. This distinguishes forms of success
// or failure after an Add/Update/Delete notification for Secrets, and
// determeins furher actions such as error handling, logging and event
// generation.
package update
package k8s
import "fmt"
......
......@@ -34,7 +34,7 @@ import (
"sync"
"code.uplex.de/k8s/k8s-crt-dnldr/pkg/pem"
"code.uplex.de/k8s/k8s-crt-dnldr/pkg/update"
// "code.uplex.de/k8s/k8s-crt-dnldr/pkg/update"
api_v1 "k8s.io/api/core/v1"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
......@@ -60,53 +60,53 @@ type NamespaceWorker struct {
wg *sync.WaitGroup
}
func (worker *NamespaceWorker) update(secret *api_v1.Secret) update.Status {
func (worker *NamespaceWorker) update(secret *api_v1.Secret) Status {
if !worker.files.Have(secret.Namespace, secret.Name, string(secret.UID),
secret.ResourceVersion) {
return update.MakeNoop("pem file currently not stored")
return MakeNoop("pem file currently not stored")
}
if worker.files.Check(secret.Namespace, secret.Name, string(secret.UID),
secret.ResourceVersion) {
return update.MakeNoop("pem file already up to date")
return MakeNoop("pem file already up to date")
}
if found, valid, err := worker.files.Write(
secret.Namespace, secret.Name, string(secret.UID),
secret.ResourceVersion); !found {
return update.MakeRecoverable("pem file not found")
return MakeRecoverable("pem file not found")
} else if !valid {
return update.MakeFatal("%v", err)
return MakeFatal("%v", err)
} else if err != nil {
if os.IsPermission(err) {
return update.MakeFatal("%s", err)
return MakeFatal("%s", err)
}
return update.MakeRecoverable("%v", err)
return MakeRecoverable("%v", err)
}
return update.MakeSuccess("pem file updated")
return MakeSuccess("pem file updated")
}
func (worker *NamespaceWorker) delete(secret *api_v1.Secret) update.Status {
func (worker *NamespaceWorker) delete(secret *api_v1.Secret) Status {
if !worker.files.Have(secret.Namespace, secret.Name, string(secret.UID),
secret.ResourceVersion) {
return update.MakeNoop("pem file currently not stored")
return MakeNoop("pem file currently not stored")
}
exist, err := worker.files.Delete(secret.Namespace, secret.Name)
if !exist {
return update.MakeNoop("pem file not found")
return MakeNoop("pem file not found")
}
if err != nil {
if os.IsPermission(err) {
return update.MakeFatal("%s", err)
return MakeFatal("%s", err)
}
return update.MakeRecoverable("%v", err)
return MakeRecoverable("%v", err)
}
return update.MakeSuccess("pem file deleted")
return MakeSuccess("pem file deleted")
}
func (worker *NamespaceWorker) syncSuccess(syncType SyncType,
secret *api_v1.Secret, status update.Status) {
secret *api_v1.Secret, status Status) {
worker.log.Infof("%s Secret %s/%s: %s", syncType, secret.Namespace,
secret.Name, status)
......@@ -115,7 +115,7 @@ func (worker *NamespaceWorker) syncSuccess(syncType SyncType,
}
func (worker *NamespaceWorker) syncFailure(syncType SyncType,
secret *api_v1.Secret, status update.Status) {
secret *api_v1.Secret, status Status) {
worker.log.Errorf("%s Secret %s/%s: %s", syncType, secret.Namespace,
secret.Name, status)
......@@ -144,29 +144,29 @@ func (worker *NamespaceWorker) next() {
}
syncType := syncObj.Type
var status update.Status
var status Status
switch syncObj.Type {
case Update:
status = worker.update(secret)
case Delete:
status = worker.delete(secret)
default:
status = update.MakeFatal("Unhandled sync: %s %s/%s", syncType,
status = MakeFatal("Unhandled sync: %s %s/%s", syncType,
secret.Namespace, secret.Name)
}
switch status.Type {
case update.Noop:
case Noop:
worker.log.Infof("%s Secret %s/%s: %s", syncType,
secret.Namespace, secret.Name, status)
worker.queue.Forget(obj)
case update.Success:
case Success:
worker.syncSuccess(syncType, secret, status)
worker.queue.Forget(obj)
case update.Fatal:
case Fatal:
worker.syncFailure(syncType, secret, status)
worker.queue.Forget(obj)
case update.Recoverable:
case Recoverable:
worker.syncFailure(syncType, secret, status)
worker.queue.AddRateLimited(obj)
}
......
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