Skip to content

Commit

Permalink
feat: address from secret
Browse files Browse the repository at this point in the history
Signed-off-by: Armin Schlegel <armin.schlegel@gmx.de>
  • Loading branch information
siredmar committed Mar 27, 2023
1 parent 5c4f151 commit 79d91e1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
5 changes: 0 additions & 5 deletions apis/edgenetwork/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ type EdgeNetworkSpec struct {
// +kubebuilder:validation:Required
SubNetwork string `json:"subNetwork"`

//The address of the server.
// Example: "example.com"
// +kubebuilder:validation:Required
Address string `json:"address"`

// Indicates the node selector to form the node pool.
// A pool's nodeSelectorTerm is not allowed to be updated.
// +kubebuilder:validation:Optional
Expand Down
1 change: 0 additions & 1 deletion examples/network.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ metadata:
name: mynetwork
namespace: myconfig
spec:
address: nats.nats.svc
network: mynetwork
subNetwork: mysubnet
limits:
Expand Down
4 changes: 0 additions & 4 deletions manifests/crds/network.edgefarm.io_edgenetworks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ spec:
spec:
description: The spec to define an edge network
properties:
address:
description: 'The address of the server. Example: "example.com"'
type: string
connectionSecretRefs:
description: The connection secrets to connect to the network
properties:
Expand Down Expand Up @@ -227,7 +224,6 @@ spec:
type: object
type: array
required:
- address
- connectionSecretRefs
- limits
- network
Expand Down
20 changes: 17 additions & 3 deletions pkg/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,11 @@ func getNatsInitContainer(config *v1alpha1.EdgeNetwork) v1.Container {
"-c",
},
Args: []string{
"cp /template/nats-server.conf /etc/nats/nats-server.conf && sed -i 's/TEMPLATE_NODE_NAME/'\"$NODE_NAME\"'/g' /etc/nats/nats-server.conf && sed -i 's/TEMPLATE_NETWORK/'\"$NETWORK\"'/g' /etc/nats/nats-server.conf && sed -i 's/TEMPLATE_SUB_NETWORK/'\"$SUB_NETWORK\"'/g' /etc/nats/nats-server.conf && sed -i 's/TEMPLATE_NETWORK/'\"$NETWORK\"'/g' /etc/nats/nats-server.conf && sed -i 's/TEMPLATE_OPERATOR_JWT/'\"$OPERATOR_JWT\"'/g' /etc/nats/nats-server.conf && sed -i 's/TEMPLATE_SYS_ACCOUNT_JWT/'\"$SYS_ACCOUNT_JWT\"'/g' /etc/nats/nats-server.conf && sed -i 's/TEMPLATE_SYS_ACCOUNT_PUBLIC_KEY/'\"$SYS_ACCOUNT_PUBLIC_KEY\"'/g' /etc/nats/nats-server.conf&& sed -i 's/TEMPLATE_ACCOUNT_PUBLIC_KEY/'\"$ACCOUNT_PUBLIC_KEY\"'/g' /etc/nats/nats-server.conf",
"cp /template/nats-server.conf /etc/nats/nats-server.conf && export ADDRESS_NO_PORT=$(echo $ADDRESS | awk -F \":\" '{print $1\":\"$2}') && sed -i 's/TEMPLATE_NODE_NAME/'\"$NODE_NAME\"'/g' /etc/nats/nats-server.conf && sed -i 's/TEMPLATE_NETWORK/'\"$NETWORK\"'/g' /etc/nats/nats-server.conf && sed -i 's/TEMPLATE_SUB_NETWORK/'\"$SUB_NETWORK\"'/g' /etc/nats/nats-server.conf && sed -i 's/TEMPLATE_NETWORK/'\"$NETWORK\"'/g' /etc/nats/nats-server.conf && sed -i 's/TEMPLATE_OPERATOR_JWT/'\"$OPERATOR_JWT\"'/g' /etc/nats/nats-server.conf && sed -i 's/TEMPLATE_SYS_ACCOUNT_JWT/'\"$SYS_ACCOUNT_JWT\"'/g' /etc/nats/nats-server.conf && sed -i 's/TEMPLATE_SYS_ACCOUNT_PUBLIC_KEY/'\"$SYS_ACCOUNT_PUBLIC_KEY\"'/g' /etc/nats/nats-server.conf && sed -i 's/TEMPLATE_ACCOUNT_PUBLIC_KEY/'\"$ACCOUNT_PUBLIC_KEY\"'/g' /etc/nats/nats-server.conf && sed -i 's#TEMPLATE_ADDRESS#'$ADDRESS_NO_PORT'#g' /etc/nats/nats-server.conf",
},
// Args: []string{
// "sleep 1000000000",
// },
Env: []v1.EnvVar{
{
Name: "NODE_NAME",
Expand Down Expand Up @@ -311,6 +314,17 @@ func getNatsInitContainer(config *v1alpha1.EdgeNetwork) v1.Container {
},
},
},
{
Name: "ADDRESS",
ValueFrom: &v1.EnvVarSource{
SecretKeyRef: &v1.SecretKeySelector{
LocalObjectReference: v1.LocalObjectReference{
Name: config.Spec.ConnectionSecretRefs.SystemUserSecretRef.Name,
},
Key: "address",
},
},
},
},
VolumeMounts: []v1.VolumeMount{
{
Expand Down Expand Up @@ -366,14 +380,14 @@ func getConfigMapForNats(config *v1alpha1.EdgeNetwork) (*v1.ConfigMap, error) {
LeafNodes: nats.LeafNodesConfig{
Remotes: []nats.LeafNodeRemoteConfig{
{
Url: fmt.Sprintf("nats://%s:7422", config.Spec.Address),
Url: "TEMPLATE_ADDRESS:7422",
Credentials: "/system-user/creds",
Account: "TEMPLATE_ACCOUNT_PUBLIC_KEY",
DenyImports: []string{"local.>"},
DenyExports: []string{"local.>"},
},
{
Url: fmt.Sprintf("nats://%s:7422", config.Spec.Address),
Url: "TEMPLATE_ADDRESS:7422",
Credentials: "/system-account-user/creds",
Account: "TEMPLATE_SYS_ACCOUNT_PUBLIC_KEY",
},
Expand Down

0 comments on commit 79d91e1

Please sign in to comment.