Skip to content

Commit

Permalink
Add support for json log format
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthik-K-N committed Sep 24, 2024
1 parent 7716671 commit 64323e9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
35 changes: 35 additions & 0 deletions docs/book/src/developer/tilt.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,41 @@ kustomize_substitutions:
IBMCLOUD_AUTH_URL: "https://iam.test.cloud.ibm.com"
```

### 4. Configuration to use observability tools

- cluster-api provides support for deploying observability tools, More information about it is available in cluster-api [book](https://cluster-api.sigs.k8s.io/developer/logging#developing-and-testing-logs).

```yaml
default_registry: "gcr.io/you-project-name-here"
deploy_observability:
- promtail
- loki
- grafana
provider_repos:
- ../cluster-api-provider-ibmcloud
enable_providers:
- ibmcloud
- kubeadm-bootstrap
- kubeadm-control-plane
kustomize_substitutions:
IBMCLOUD_API_KEY: "XXXXXXXXXXXXXXXXXX"
PROVIDER_ID_FORMAT: "v2"
EXP_CLUSTER_RESOURCE_SET: "true"
extra_args:
core:
- "--logging-format=json"
- "--v=5"
kubeadm-bootstrap:
- "--v=5"
- "--logging-format=json"
kubeadm-control-plane:
- "--v=5"
- "--logging-format=json"
ibmcloud:
- "--v=5"
- "--logging-format=json"
```

**NOTE**: For information about all the fields that can be used in the `tilt-settings.yaml` file, check them [here](https://cluster-api.sigs.k8s.io/developer/tilt.html#tilt-settings-fields).

## Run Tilt
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ require (
k8s.io/apimachinery v0.30.3
k8s.io/cli-runtime v0.30.3
k8s.io/client-go v0.30.3
k8s.io/component-base v0.30.3
k8s.io/klog/v2 v2.120.1
k8s.io/utils v0.0.0-20231127182322-b307cd553661
sigs.k8s.io/cluster-api v1.8.3
Expand Down Expand Up @@ -80,6 +81,7 @@ require (
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/analysis v0.21.5 // indirect
github.com/go-openapi/errors v0.22.0 // indirect
github.com/go-openapi/jsonpointer v0.20.1 // indirect
Expand Down Expand Up @@ -162,6 +164,7 @@ require (
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.8.0 // indirect
Expand All @@ -180,7 +183,6 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiserver v0.30.3 // indirect
k8s.io/cluster-bootstrap v0.30.3 // indirect
k8s.io/component-base v0.30.3 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.0 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
Expand Down
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
cgrecord "k8s.io/client-go/tools/record"
"k8s.io/component-base/logs"
logsv1 "k8s.io/component-base/logs/api/v1"
"k8s.io/klog/v2"

ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -48,6 +50,7 @@ import (
"sigs.k8s.io/cluster-api-provider-ibmcloud/pkg/record"

_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
_ "k8s.io/component-base/logs/json/register"
)

var (
Expand All @@ -56,6 +59,7 @@ var (
healthAddr string
syncPeriod time.Duration
managerOptions = flags.ManagerOptions{}
logOptions = logs.NewOptions()
webhookPort int
webhookCertDir string

Expand Down Expand Up @@ -126,6 +130,7 @@ func initFlags(fs *pflag.FlagSet) {
fs.StringVar(&webhookCertDir, "webhook-cert-dir", "/tmp/k8s-webhook-server/serving-certs/",
"The webhook certificate directory, where the server should find the TLS certificate and key.")

logsv1.AddFlags(logOptions, fs)
flags.AddManagerOptions(fs, &managerOptions)
}

Expand All @@ -139,6 +144,12 @@ func validateFlags() error {
default:
return fmt.Errorf("invalid value for flag provider-id-fmt: %s, Supported values: %s, %s ", options.ProviderIDFormat, options.ProviderIDFormatV1, options.ProviderIDFormatV2)
}

if err := logsv1.ValidateAndApply(logOptions, nil); err != nil {
setupLog.Error(err, "unable to validate and apply log options")
return err
}

return nil
}

Expand Down

0 comments on commit 64323e9

Please sign in to comment.