Skip to content

Commit

Permalink
chore: fix comments
Browse files Browse the repository at this point in the history
Signed-off-by: jacky-xbb <[email protected]>
  • Loading branch information
jacky-xbb committed Nov 7, 2023
1 parent 692727f commit d3f52dd
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 17 deletions.
4 changes: 2 additions & 2 deletions apis/apps/v2beta1/emqx_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ type BootstrapAPIKey struct {
}

type SecretRef struct {
Key *KeyRef `json:"key"`
Secret *KeyRef `json:"secret"`
Key KeyRef `json:"key"`
Secret KeyRef `json:"secret"`
}

type KeyRef struct {
Expand Down
14 changes: 3 additions & 11 deletions apis/apps/v2beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions controllers/apps/v2beta1/add_bootstrap_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"

appsv2beta1 "github.com/emqx/emqx-operator/apis/apps/v2beta1"
innerReq "github.com/emqx/emqx-operator/internal/requester"
Expand Down Expand Up @@ -87,17 +88,22 @@ func ReadSecret(k8sClient client.Client, ctx context.Context, namespace string,
}

func generateBootstrapAPIKeySecret(k8sClient client.Client, ctx context.Context, instance *appsv2beta1.EMQX) *corev1.Secret {
logger := log.FromContext(ctx)
bootstrapAPIKeys := ""

for _, apiKey := range instance.Spec.BootstrapAPIKeys {
if apiKey.SecretRef != nil {
logger.V(1).Info("Read SecretRef")

// Read key and secret values from the refenced secrets
keyValue, err := ReadSecret(k8sClient, ctx, instance.Namespace, apiKey.SecretRef.Key.SecretName, apiKey.SecretRef.Key.SecretKey)
if err != nil {
logger.V(1).Error(err, "read secretRef", "key")
continue
}
secretValue, err := ReadSecret(k8sClient, ctx, instance.Namespace, apiKey.SecretRef.Secret.SecretName, apiKey.SecretRef.Secret.SecretKey)
if err != nil {
logger.V(1).Error(err, "read secretRef", "secret")
continue
}
bootstrapAPIKeys += keyValue + ":" + secretValue + "\n"
Expand Down
4 changes: 2 additions & 2 deletions controllers/apps/v2beta1/add_bootstrap_resource_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ var _ = Describe("AddBootstrap", Ordered, Label("bootstrap"), func() {
instance.Spec.BootstrapAPIKeys = []appsv2beta1.BootstrapAPIKey{
{
SecretRef: &appsv2beta1.SecretRef{
Key: &appsv2beta1.KeyRef{
Key: appsv2beta1.KeyRef{
// Note: a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters
SecretName: "test-key-secret",
SecretKey: "key",
},
Secret: &appsv2beta1.KeyRef{
Secret: appsv2beta1.KeyRef{
SecretName: "test-value-secret",
SecretKey: "secret",
},
Expand Down
4 changes: 2 additions & 2 deletions controllers/apps/v2beta1/add_bootstrap_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ func TestGenerateBootstrapAPIKeySecretWithSecretRef(t *testing.T) {
BootstrapAPIKeys: []appsv2beta1.BootstrapAPIKey{
{
SecretRef: &appsv2beta1.SecretRef{
Key: &appsv2beta1.KeyRef{
Key: appsv2beta1.KeyRef{
SecretName: "test-key-secret",
SecretKey: "key",
},
Secret: &appsv2beta1.KeyRef{
Secret: appsv2beta1.KeyRef{
SecretName: "test-value-secret",
SecretKey: "secret",
},
Expand Down
4 changes: 4 additions & 0 deletions docs/en_US/reference/v2beta1-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ _Appears in:_
_Appears in:_
- [SecretRef](#secretref)

| Field | Description |
| --- | --- |
| `secretName` _string_ | |
| `secretKey` _string_ | |


#### NodeEvacuationStats
Expand Down
4 changes: 4 additions & 0 deletions docs/zh_CN/reference/v2beta1-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ _Appears in:_
_Appears in:_
- [SecretRef](#secretref)

| Field | Description |
| --- | --- |
| `secretName` _string_ | |
| `secretKey` _string_ | |


#### NodeEvacuationStats
Expand Down

0 comments on commit d3f52dd

Please sign in to comment.