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

feat(operator): polish KeptnConfig and use Env Var for initial configuration #1097

Merged
merged 12 commits into from
Mar 27, 2023
2 changes: 1 addition & 1 deletion docs/content/en/docs/crd-ref/options/v1alpha1/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ _Appears in:_
| Field | Description |
| --- | --- |
| `OTelCollectorUrl` _string_ | OTelCollectorUrl can be used to set the Open Telemetry collector that the operator should use |
| `keptnAppCreationRequestTimeout` _integer_ | KeptnAppCreationRequestTimeout is used to set the interval in which automatic app discovery searches for workload to put into the same auto-generated KeptnApp |
| `keptnAppCreationRequestTimeoutSeconds` _integer_ | KeptnAppCreationRequestTimeout is used to set the interval in which automatic app discovery searches for workload to put into the same auto-generated KeptnApp |



Expand Down
4 changes: 3 additions & 1 deletion operator/apis/options/v1alpha1/keptnconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ type KeptnConfigSpec struct {
// Important: Run "make" to regenerate code after modifying this file

// OTelCollectorUrl can be used to set the Open Telemetry collector that the operator should use
// +optional
OTelCollectorUrl string `json:"OTelCollectorUrl,omitempty"`
// KeptnAppCreationRequestTimeout is used to set the interval in which automatic app discovery
// searches for workload to put into the same auto-generated KeptnApp
// +kubebuilder:default:=30
KeptnAppCreationRequestTimeout uint `json:"keptnAppCreationRequestTimeout,omitempty"`
// +optional
KeptnAppCreationRequestTimeoutSeconds uint `json:"keptnAppCreationRequestTimeoutSeconds,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls also change the docs string when you change the variable name here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha: #1126

}

// KeptnConfigStatus defines the observed state of KeptnConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ spec:
description: OTelCollectorUrl can be used to set the Open Telemetry
collector that the operator should use
type: string
keptnAppCreationRequestTimeout:
keptnAppCreationRequestTimeoutSeconds:
default: 30
description: KeptnAppCreationRequestTimeout is used to set the interval
in which automatic app discovery searches for workload to put into
Expand Down
4 changes: 2 additions & 2 deletions operator/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: OTEL_COLLECTOR_URL
value: otel-collector:4317
- name: FUNCTION_RUNNER_IMAGE
value: ghcr.keptn.sh/keptn/functions-runtime:v0.7.0 #x-release-please-version
- name: OTEL_COLLECTOR_URL
value: otel-collector:4317
- name: KEPTN_APP_CONTROLLER_LOG_LEVEL
value: "0"
- name: KEPTN_APP_VERSION_CONTROLLER_LOG_LEVEL
Expand Down
2 changes: 2 additions & 0 deletions operator/config/samples/options_v1alpha1_keptnconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ metadata:
app.kubernetes.io/part-of: keptn-lifecycle-toolkit
app.kuberentes.io/managed-by: kustomize
app.kubernetes.io/created-by: keptn-lifecycle-toolkit
control-plane: lifecycle-operator
name: keptnconfig-sample
spec:
OTelCollectorUrl: 'otel-collector:4317'
keptnAppCreationRequestTimeoutSeconds: 30
9 changes: 5 additions & 4 deletions operator/controllers/options/keptnconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ import (
// KeptnConfigReconciler reconciles a KeptnConfig object
type KeptnConfigReconciler struct {
client.Client
Scheme *runtime.Scheme
Log logr.Logger
LastAppliedSpec *optionsv1alpha1.KeptnConfigSpec
Scheme *runtime.Scheme
Log logr.Logger
LastAppliedSpec *optionsv1alpha1.KeptnConfigSpec
DefaultCollectorURL string
}

// +kubebuilder:rbac:groups=options.keptn.sh,resources=keptnconfigs,verbs=get;list;watch;create;update;patch;delete
Expand Down Expand Up @@ -88,7 +89,7 @@ func (r *KeptnConfigReconciler) reconcileOtelCollectorUrl(config *optionsv1alpha

func (r *KeptnConfigReconciler) initConfig() {
r.LastAppliedSpec = &optionsv1alpha1.KeptnConfigSpec{
OTelCollectorUrl: "",
OTelCollectorUrl: r.DefaultCollectorURL,
}
}

Expand Down
11 changes: 7 additions & 4 deletions operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ type envConfig struct {
KeptnTaskDefinitionControllerLogLevel int `envconfig:"KEPTN_TASK_DEFINITION_CONTROLLER_LOG_LEVEL" default:"0"`
KeptnWorkloadControllerLogLevel int `envconfig:"KEPTN_WORKLOAD_CONTROLLER_LOG_LEVEL" default:"0"`
KeptnWorkloadInstanceControllerLogLevel int `envconfig:"KEPTN_WORKLOAD_INSTANCE_CONTROLLER_LOG_LEVEL" default:"0"`
KptnOptionsControllerLogLevel int `envconfig:"OPTIONS_CONTROLLER_LOG_LEVEL" default:"0"`
KeptnOptionsControllerLogLevel int `envconfig:"OPTIONS_CONTROLLER_LOG_LEVEL" default:"0"`

KeptnOptionsCollectorURL string `envconfig:"OTEL_COLLECTOR_URL" default:""`
}

//nolint:funlen,gocognit,gocyclo
Expand Down Expand Up @@ -259,9 +261,10 @@ func main() {

configLogger := ctrl.Log.WithName("KeptnConfig Controller")
configReconciler := &controlleroptions.KeptnConfigReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Log: configLogger.V(env.KptnOptionsControllerLogLevel),
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Log: configLogger.V(env.KeptnOptionsControllerLogLevel),
DefaultCollectorURL: env.KeptnOptionsCollectorURL,
}
if err = (configReconciler).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "KeptnConfig")
Expand Down