Skip to content

Commit 8a23b7b

Browse files
committed
Inline doc overhaul
Trying to make the inline doc more accurate, and to document the less obvious things.
1 parent f98c0ed commit 8a23b7b

File tree

8 files changed

+42
-24
lines changed

8 files changed

+42
-24
lines changed

config/config.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"k8s.io/client-go/rest"
1111
)
1212

13-
// KfConfig is the configuration struct, passed to controllers's Init()
13+
// KfConfig holds the configuration options passed at launch time (and the rest client)
1414
type KfConfig struct {
15-
// When DryRun is true, we display but don't really send notifications
15+
// When DryRun is true, we don't write to disk and we don't commit/push
1616
DryRun bool
1717

1818
// Logger should be used to send all logs
@@ -21,7 +21,7 @@ type KfConfig struct {
2121
// Client represents a connection to a Kubernetes cluster
2222
Client *rest.Config
2323

24-
// GitURL is the address of the git repository
24+
// GitURL is the address of a remote git repository
2525
GitURL string
2626

2727
// LocalDir is the local path where we'll serialize cluster objets

pkg/client/client.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Package client initialize a Kubernete's client-go rest.Config or clientset
1+
// Package client initialize a Kubernete's client-go rest.Config or clientset
22
package client
33

44
import (
@@ -14,9 +14,9 @@ import (
1414
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
1515
)
1616

17-
// NewRestConfig create a *rest.Config, using the kubectl paths and priorities:
18-
// - Command line flags (api-server and/or kubeconfig path) have higher priorities
19-
// - Else, use the config file path in KUBECONFIG environment variable, if any
17+
// NewRestConfig create a *rest.Config, trying to mimic kubectl behavior:
18+
// - Explicit user provided api-server (and/or kubeconfig path) have higher priorities
19+
// - Else, use the config file path in KUBECONFIG environment variable (if any)
2020
// - Else, use the config file in ~/.kube/config, if any
2121
// - Else, consider we're running in cluster (in a pod), and use the pod's service
2222
// account and cluster's kubernetes.default service.
@@ -45,8 +45,6 @@ func NewRestConfig(apiserver string, kubeconfig string) (*rest.Config, error) {
4545
}
4646

4747
// NewClientSet create a clientset (a client connection to a Kubernetes cluster).
48-
// It will connect using the optional apiserver or kubeconfig options, or will
49-
// default to the automatic, in cluster settings.
5048
func NewClientSet(apiserver string, kubeconfig string) (*kubernetes.Clientset, error) {
5149
config, err := NewRestConfig(apiserver, kubeconfig)
5250
if err != nil {

pkg/controller/controller.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Package controller list and keep watching a specific Kubernetes resource kind
2+
// (ie. "apps/v1 Deployment", "v1 Namespace", etc) and notifies a recorder whenever
3+
// a change happens (an object changed, was created, or deleted). This is a generic
4+
// implementation: the resource kind to watch is provided at runtime. We should
5+
// start several such controllers to watch for distinct resources.
16
package controller
27

38
import (
@@ -159,7 +164,7 @@ func (c *Controller) processItem(key string) error {
159164

160165
obj := rawobj.(*unstructured.Unstructured).DeepCopy()
161166

162-
// clean non exportable fields
167+
// clear irrelevant attributes
163168
uc := obj.UnstructuredContent()
164169
md := uc["metadata"].(map[string]interface{})
165170
delete(uc, "status")

pkg/controller/observer.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package controller
22

3+
// An observer polls the Kubernetes api-server to discover all supported
4+
// API groups/object kinds, and launch a new controller for each of them.
5+
// Due to CRD/TPR, new API groups / object kinds may appear at any time,
6+
// that's why we keep polling the API server.
7+
38
import (
49
"fmt"
510
"strings"
@@ -18,7 +23,7 @@ import (
1823

1924
const discoveryInterval = 60 * time.Second
2025

21-
// Observer manage kubernetes controllers
26+
// Observer watch api-server and manage kubernetes controllers
2227
type Observer struct {
2328
stop chan struct{}
2429
done chan struct{}
@@ -39,7 +44,8 @@ type gvk struct {
3944

4045
type resources map[string]*gvk
4146

42-
// NewObserver creates a new observer, to create an manage Kubernetes controllers
47+
// NewObserver returns a new observer, that will watch for api resource kinds
48+
// and create new controllers for each one.
4349
func NewObserver(config *config.KfConfig, evch chan Event) *Observer {
4450
return &Observer{
4551
config: config,
@@ -164,7 +170,7 @@ func (c *Observer) expandAndFilterAPIResources(groups []*metav1.APIResourceList)
164170
}
165171

166172
// remove lower priorities "cohabitations". cf. kubernetes/cmd/kube-apiserver/app/server.go
167-
// (the api server may expose some resources under several api groups for backward compat...)
173+
// (the api-server may expose a resource under several api groups, for backward compat)
168174
for preferred, obsolete := range preferredVersions {
169175
if _, ok := resources[preferred]; ok {
170176
delete(resources, obsolete)

pkg/health/health.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Package health serves healthchecks over HTTP at /health endpoint.
1+
// Package health serves health checks over HTTP at /health endpoint.
22
package health
33

44
import (

pkg/recorder/recorder.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Package recorder listen for events notification from controllers,
2+
// and persists those events' content as files on disk.
13
package recorder
24

35
import (
@@ -12,6 +14,9 @@ import (
1214
"github.com/bpineau/katafygio/pkg/controller"
1315
)
1416

17+
// activeFiles will contain a list of active (present in cluster) objets; we'll
18+
// use that to periodically find and garbage collect stale objets in the git repos
19+
// (ie. if some objects were delete from cluster while katafygio was not running).
1520
type activeFiles map[string]bool
1621

1722
// Listener receive events from controllers and save them to disk as yaml files
@@ -33,7 +38,7 @@ func New(config *config.KfConfig, evchan chan controller.Event) *Listener {
3338
}
3439
}
3540

36-
// Start receive events and persists them to disk as files
41+
// Start receive events and saves them to disk as files
3742
func (w *Listener) Start() *Listener {
3843
w.config.Logger.Info("Starting event recorder")
3944
err := os.MkdirAll(filepath.Clean(w.config.LocalDir), 0700)

pkg/run/run.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Package run implements the main katafygio's loop, by
2-
// the services and controllers.
1+
// Package run implements the main katafygio's loop, starting and
2+
// stopping all services and controllers.
33
package run
44

55
import (

pkg/store/git/git.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
// I'd love a working pure Go implementation. I can't find any though, src-d/go-git
2-
// being innapropriate due to https://github.com/src-d/go-git/issues/793 and
3-
// https://github.com/src-d/go-git/issues/785 .
4-
5-
// Package git stores changes a in a git repository
1+
// We'd love a working pure Go implementation. But so far we didn't find any
2+
// that would work for us. src-d/go-git is innapropriate due to
3+
// https://github.com/src-d/go-git/issues/793 and
4+
// https://github.com/src-d/go-git/issues/785 . And binding to the libgit C lib
5+
// aren't pure Go either. So we need the git binary for now.
6+
7+
// Package git makes a git repository out of a local directory, keeps the
8+
// content committed when the directory changes, and optionaly (if a remote
9+
// repos url is provided), keep it in sync with a remote repository.
610
package git
711

812
import (
@@ -34,13 +38,13 @@ type Store struct {
3438
donech chan struct{}
3539
}
3640

37-
// New instantiate a new Store
41+
// New instantiate a new git Store
3842
func New(config *config.KfConfig) *Store {
3943
return &Store{
4044
Logger: config.Logger,
4145
URL: config.GitURL,
4246
LocalDir: config.LocalDir,
43-
Author: "Katafygio", // XXX maybe this could be a cli option
47+
Author: "Katafygio", // XXX should we expose a cli option for that?
4448
Email: "katafygio@localhost",
4549
Msg: "Kubernetes cluster change",
4650
DryRun: config.DryRun,

0 commit comments

Comments
 (0)