Skip to content

Commit

Permalink
rename api key to agent key
Browse files Browse the repository at this point in the history
  • Loading branch information
IridiumOxide committed Oct 17, 2023
1 parent edab448 commit ee317c0
Show file tree
Hide file tree
Showing 23 changed files with 89 additions and 30 deletions.
2 changes: 1 addition & 1 deletion docs/agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ empty schema

| Name | Type | Go type | Required | Default | Description | Example |
| ----------------- | ------------------------------ | -------------- | :------: | ------- | ----------------------------------------------------------------------------------------------------------------------------- | ------- |
| APIKey | string | `string` | | | API Key for this agent. If this key is not set, the extension won't be enabled. | |
| AgentAPIKey | string | `string` | | | API Key for this agent. If this key is not set, the extension won't be enabled. | |
| Endpoint | string | `string` | | | Address to gRPC or HTTP(s) server listening in agent service. To use HTTP protocol, the address must start with `http(s)://`. | |
| HeartbeatInterval | string (formatted string) | `string` | | | Interval between each heartbeat. | |
| InstallationMode | string | `string` | | | Installation mode describes on which underlying platform the Agent or the Controller is being run. | |
Expand Down
2 changes: 1 addition & 1 deletion docs/content/get-started/installation/agent/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Below are the instructions to install the Aperture Agent on Docker.
fluxninja:
enable_cloud_controller: true
endpoint: "ORGANIZATION_NAME.app.fluxninja.com:443"
api_key: AGENT_API_KEY
agent_api_key: AGENT_API_KEY
log:
level: info
pretty_console: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ agent:
By following these instructions, you will have deployed the Aperture Agent into
your cluster.
1. Configure the Aperture Cloud endpoint and API key parameters in the Agent.
1. Configure the Aperture Cloud endpoint and Agent Key parameters in the Agent.
Update the `values.yaml` file and pass it with the `install` command:
```yaml
Expand Down
2 changes: 1 addition & 1 deletion docs/content/get-started/self-hosting/agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ as release name. If your setup is different, adjust these endpoints accordingly.
fluxninja:
enable_cloud_controller: false
endpoint: "ORGANIZATION_NAME.app.fluxninja.com:443"
api_key: API_KEY
agent_api_key: AGENT_API_KEY
etcd:
endpoints: ["http://etcd:2379"]
prometheus:
Expand Down
12 changes: 12 additions & 0 deletions docs/content/reference/configuration/agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,18 @@ FluxNinjaExtensionConfig is the configuration for

<!-- vale on -->

Deprecated: use agent_api_key instead

</dd>
<dt>agent_api_key</dt>
<dd>

<!-- vale off -->

(string)

<!-- vale on -->

API Key for this agent. If this key is not set, the extension won't be enabled.

</dd>
Expand Down
12 changes: 12 additions & 0 deletions docs/content/reference/configuration/controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,18 @@ FluxNinjaExtensionConfig is the configuration for

<!-- vale on -->

Deprecated: use agent_api_key instead

</dd>
<dt>agent_api_key</dt>
<dd>

<!-- vale off -->

(string)

<!-- vale on -->

API Key for this agent. If this key is not set, the extension won't be enabled.

</dd>
Expand Down
4 changes: 2 additions & 2 deletions docs/content/reference/fluxninja.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ installation of the Aperture Controller or Agent:
</TabItem>
</Tabs>

Replace the values of `ORGANIZATION_NAME` and `API_KEY` with the actual values
of the organization on Aperture Cloud and API Key generated on it.
Replace the values of `ORGANIZATION_NAME` and `AGENT_KEY` with the actual values
of the organization on Aperture Cloud and Agent Key generated on it.

:::note

Expand Down
2 changes: 1 addition & 1 deletion docs/controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ empty schema

| Name | Type | Go type | Required | Default | Description | Example |
| ----------------- | ------------------------------ | -------------- | :------: | ------- | ----------------------------------------------------------------------------------------------------------------------------- | ------- |
| APIKey | string | `string` | | | API Key for this agent. If this key is not set, the extension won't be enabled. | |
| AgentAPIKey | string | `string` | | | API Key for this agent. If this key is not set, the extension won't be enabled. | |
| Endpoint | string | `string` | | | Address to gRPC or HTTP(s) server listening in agent service. To use HTTP protocol, the address must start with `http(s)://`. | |
| HeartbeatInterval | string (formatted string) | `string` | | | Interval between each heartbeat. | |
| InstallationMode | string | `string` | | | Installation mode describes on which underlying platform the Agent or the Controller is being run. | |
Expand Down
7 changes: 6 additions & 1 deletion docs/gen/config/extensions/fluxninja/extension-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,14 @@ definitions:
x-go-package: github.com/fluxninja/aperture/v2/pkg/config
FluxNinjaExtensionConfig:
properties:
api_key:
agent_api_key:
description: API Key for this agent. If this key is not set, the extension won't be enabled.
type: string
x-go-name: AgentAPIKey
x-go-tag-json: agent_api_key
api_key:
description: 'Deprecated: use agent_api_key instead'
type: string
x-go-name: APIKey
x-go-tag-json: api_key
client:
Expand Down
10 changes: 8 additions & 2 deletions extensions/fluxninja/extconfig/extconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ type FluxNinjaExtensionConfig struct {
// For connecting to Aperture Cloud Controller, the `endpoint` should be a `grpc/http2` address.
// For self-hosted controller, the HTTP protocol address can start with `http(s)://`.
Endpoint string `json:"endpoint" validate:"omitempty,hostname_port|url|fqdn"`
// API Key for this agent. If this key is not set, the extension won't be enabled.
// Deprecated: use agent_api_key instead
APIKey string `json:"api_key"`
// API Key for this agent. If this key is not set, the extension won't be enabled.
AgentAPIKey string `json:"agent_api_key"`
// Installation mode describes on which underlying platform the Agent or the Controller is being run.
InstallationMode string `json:"installation_mode" validate:"oneof=KUBERNETES_SIDECAR KUBERNETES_DAEMONSET LINUX_BARE_METAL" default:"LINUX_BARE_METAL"`
// Whether to connect to [Aperture Cloud Controller](/reference/fluxninja.md).
Expand Down Expand Up @@ -78,12 +80,16 @@ func provideConfig(unmarshaller config.Unmarshaller) (*FluxNinjaExtensionConfig,

func provideEtcdConfigOverride(extensionConfig *FluxNinjaExtensionConfig) *etcdclient.ConfigOverride {
if extensionConfig.EnableCloudController {
apiKey := extensionConfig.AgentAPIKey
if apiKey == "" {
apiKey = extensionConfig.APIKey
}
return &etcdclient.ConfigOverride{
Namespace: "",
Endpoints: []string{extensionConfig.Endpoint},
PerRPCCredentials: perRPCHeaders{
headers: map[string]string{
"apiKey": extensionConfig.APIKey,
"apiKey": apiKey,
},
},
OverriderName: "fluxninja extension",
Expand Down
14 changes: 9 additions & 5 deletions extensions/fluxninja/heartbeats/heartbeats.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type Heartbeats struct {
flowControlPoints *cache.Cache[selectors.TypedControlPointID]
agentInfo *agentinfo.AgentInfo
election *election.Election
APIKey string
apiKey string
jobName string
installationMode string
heartbeatsAddr string
Expand All @@ -81,10 +81,14 @@ func newHeartbeats(
flowControlPoints *cache.Cache[selectors.TypedControlPointID],
autoscalek8sControlPoints autoscalek8sdiscovery.AutoScaleControlPoints,
) *Heartbeats {
apiKey := extensionConfig.AgentAPIKey
if apiKey == "" {
apiKey = extensionConfig.APIKey
}
return &Heartbeats{
heartbeatsAddr: extensionConfig.Endpoint,
interval: extensionConfig.HeartbeatInterval,
APIKey: extensionConfig.APIKey,
apiKey: apiKey,
jobGroup: jobGroup,
statusRegistry: statusRegistry,
entities: entities,
Expand Down Expand Up @@ -255,8 +259,8 @@ func (h *Heartbeats) newHeartbeat(
func (h *Heartbeats) sendSingleHeartbeat(jobCtxt context.Context) (proto.Message, error) {
report := h.newHeartbeat(jobCtxt)

// Add api key value to metadata
md := metadata.Pairs("apiKey", h.APIKey)
// Add agent key value to metadata
md := metadata.Pairs("apiKey", h.apiKey)
ctx := metadata.NewOutgoingContext(jobCtxt, md)
_, err := h.heartbeatsClient.Report(ctx, report)
if err != nil {
Expand All @@ -280,7 +284,7 @@ func (h *Heartbeats) sendSingleHeartbeatByHTTP(jobCtxt context.Context) (proto.M
log.Warn().Err(err).Msg("could not create request")
return &emptypb.Empty{}, err
}
req.Header.Add("apiKey", h.APIKey)
req.Header.Add("apiKey", h.apiKey)
cli := http.DefaultClient
cli.Transport = &http.Transport{}
_, err = cli.Do(req)
Expand Down
6 changes: 5 additions & 1 deletion extensions/fluxninja/heartbeats/peers-watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ func setupPeersWatcher(
sessionScopedKV *etcdclient.SessionScopedKV,
lc fx.Lifecycle,
) (PeersOut, error) {
if extensionConfig.APIKey == "" {
apiKey := extensionConfig.AgentAPIKey
if apiKey == "" {
apiKey = extensionConfig.APIKey
}
if apiKey == "" {
return PeersOut{}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions extensions/fluxninja/heartbeats/provide.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ type ConstructorIn struct {

// provide provides a new instance of Heartbeats.
func provide(in ConstructorIn) (*Heartbeats, error) {
if in.ExtensionConfig.APIKey == "" {
log.Info().Msg("Heartbeats API key not set, skipping")
if in.ExtensionConfig.AgentAPIKey == "" && in.ExtensionConfig.APIKey == "" {
log.Info().Msg("Heartbeats Agent Key not set, skipping")
return nil, nil
}

Expand Down
4 changes: 2 additions & 2 deletions extensions/fluxninja/otel/otel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ var _ = DescribeTable("FN Extension OTel", func(
) {
cfg := map[string]interface{}{
"fluxninja": map[string]interface{}{
"api_key": "deadbeef",
"endpoint": "http://localhost:1234",
"agent_api_key": "deadbeef",
"endpoint": "http://localhost:1234",
},
}
marshalledCfg, err := json.Marshal(cfg)
Expand Down
8 changes: 6 additions & 2 deletions extensions/fluxninja/otel/provide.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func injectOtelConfig(
extensionConfig *extconfig.FluxNinjaExtensionConfig,
configProvider *otelconfig.Provider,
) {
if extensionConfig.APIKey == "" {
if extensionConfig.AgentAPIKey == "" && extensionConfig.APIKey == "" {
return
}

Expand Down Expand Up @@ -226,10 +226,14 @@ func addFluxNinjaExporter(config *otelconfig.Config,
grpcClientConfig *grpcclient.GRPCClientConfig,
httpClientConfig *httpclient.HTTPClientConfig,
) {
apiKey := extensionConfig.AgentAPIKey
if apiKey == "" {
apiKey = extensionConfig.APIKey
}
cfg := map[string]interface{}{
"endpoint": extensionConfig.Endpoint,
"headers": map[string]interface{}{
"authorization": fmt.Sprintf("Bearer %s", extensionConfig.APIKey),
"authorization": fmt.Sprintf("Bearer %s", apiKey),
},
"sending_queue": map[string]interface{}{
// Needed to avoid sending metrics out of order, which leads to metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1164,10 +1164,13 @@ spec:
fluxninja:
description: FluxNinja extension configuration.
properties:
api_key:
agent_api_key:
description: API Key for this agent. If this key is not set,
the extension won't be enabled.
type: string
api_key:
description: 'Deprecated: use agent_api_key instead'
type: string
client:
description: Client configuration.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ spec:
- name: APERTURE_AGENT_SERVICE_DISCOVERY_KUBERNETES_ENABLED
value: "false"
{{- if or (and .Values.agent.secrets.fluxNinjaExtension .Values.agent.secrets.fluxNinjaExtension.create) (and .Values.agent.secrets.fluxNinjaExtension .Values.agent.secrets.fluxNinjaExtension.secretKeyRef .Values.agent.secrets.fluxNinjaExtension.secretKeyRef.name) }}
- name: APERTURE_AGENT_FLUXNINJA_API_KEY
- name: APERTURE_AGENT_FLUXNINJA_AGENT_KEY
valueFrom:
secretKeyRef:
name: {{ include "agent.apiSecret.name" (dict "agent" .Values.agent "context" . $ ) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1048,10 +1048,13 @@ spec:
fluxninja:
description: FluxNinja extension configuration.
properties:
api_key:
agent_api_key:
description: API Key for this agent. If this key is not set,
the extension won't be enabled.
type: string
api_key:
description: 'Deprecated: use agent_api_key instead'
type: string
client:
description: Client configuration.
properties:
Expand Down
5 changes: 4 additions & 1 deletion operator/config/crd/bases/fluxninja.com_agents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1164,10 +1164,13 @@ spec:
fluxninja:
description: FluxNinja extension configuration.
properties:
api_key:
agent_api_key:
description: API Key for this agent. If this key is not set,
the extension won't be enabled.
type: string
api_key:
description: 'Deprecated: use agent_api_key instead'
type: string
client:
description: Client configuration.
properties:
Expand Down
5 changes: 4 additions & 1 deletion operator/config/crd/bases/fluxninja.com_controllers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1048,10 +1048,13 @@ spec:
fluxninja:
description: FluxNinja extension configuration.
properties:
api_key:
agent_api_key:
description: API Key for this agent. If this key is not set,
the extension won't be enabled.
type: string
api_key:
description: 'Deprecated: use agent_api_key instead'
type: string
client:
description: Client configuration.
properties:
Expand Down
2 changes: 1 addition & 1 deletion operator/controllers/agent/config_test.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ auto_scale:
kubernetes:
enabled: false
fluxninja:
api_key: ""
agent_api_key: ""
client:
grpc:
backoff:
Expand Down
2 changes: 1 addition & 1 deletion operator/controllers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func AgentEnv(instance *agentv1alpha1.Agent, agentGroup string) []corev1.EnvVar

if instance.Spec.Secrets.FluxNinjaExtension.Create || instance.Spec.Secrets.FluxNinjaExtension.SecretKeyRef.Name != "" {
envs = append(envs, corev1.EnvVar{
Name: "APERTURE_AGENT_FLUXNINJA_API_KEY",
Name: "APERTURE_AGENT_FLUXNINJA_AGENT_KEY",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Expand Down
2 changes: 1 addition & 1 deletion operator/controllers/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ var _ = Describe("Tests for agentEnv", func() {
Value: "true",
},
{
Name: "APERTURE_AGENT_FLUXNINJA_API_KEY",
Name: "APERTURE_AGENT_FLUXNINJA_AGENT_KEY",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Expand Down

0 comments on commit ee317c0

Please sign in to comment.