generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read the cluster domain from the Eventing CR or from the ConfigMap (#152
) * Read the cluster domain from the Eventing CR or from the ConfigMap * Format imports * Fix lint issues * Fix lint issues * Fix tests after rebase * Simplify code * Fix tests
- Loading branch information
1 parent
7142bc1
commit 08b9ec6
Showing
32 changed files
with
743 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package eventing | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
const ( | ||
shootInfoConfigMapName = "shoot-info" | ||
shootInfoConfigMapNamespace = "kube-system" | ||
shootInfoConfigMapKeyDomain = "domain" | ||
domainMissingMessageFormat = `domain configuration is missing. domain must be configured in either the Eventing` + | ||
` CustomResource under "Spec.Backend.Config.Domain" or in the ConfigMap "%s/%s" under "data.%s"` | ||
domainMissingMessageFormatWithError = domainMissingMessageFormat + `: %v` | ||
) | ||
|
||
func (r *Reconciler) readDomainFromConfigMap(ctx context.Context) (string, error) { | ||
cm, err := r.kubeClient.GetConfigMap(ctx, shootInfoConfigMapName, shootInfoConfigMapNamespace) | ||
if err != nil { | ||
return "", err | ||
} | ||
return cm.Data[shootInfoConfigMapKeyDomain], nil | ||
} | ||
|
||
func domainMissingError(err error) error { | ||
if err != nil { | ||
return fmt.Errorf( | ||
domainMissingMessageFormatWithError, | ||
shootInfoConfigMapNamespace, shootInfoConfigMapName, shootInfoConfigMapKeyDomain, err, | ||
) | ||
} | ||
|
||
return fmt.Errorf( | ||
domainMissingMessageFormat, | ||
shootInfoConfigMapNamespace, shootInfoConfigMapName, shootInfoConfigMapKeyDomain, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package eventing | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
corev1 "k8s.io/api/core/v1" | ||
|
||
k8smocks "github.com/kyma-project/eventing-manager/pkg/k8s/mocks" | ||
"github.com/kyma-project/eventing-manager/test/utils" | ||
) | ||
|
||
func Test_readDomainFromConfigMap(t *testing.T) { | ||
// given | ||
ctx := context.TODO() | ||
|
||
cm := &corev1.ConfigMap{ | ||
Data: map[string]string{ | ||
shootInfoConfigMapKeyDomain: utils.Domain, | ||
}, | ||
} | ||
|
||
kubeClient := func() *k8smocks.Client { | ||
kubeClient := new(k8smocks.Client) | ||
kubeClient.On("GetConfigMap", ctx, shootInfoConfigMapName, shootInfoConfigMapNamespace). | ||
Return(cm, nil).Once() | ||
return kubeClient | ||
} | ||
|
||
wantError := error(nil) | ||
wantDomain := utils.Domain | ||
|
||
// when | ||
r := &Reconciler{kubeClient: kubeClient()} | ||
gotDomain, gotError := r.readDomainFromConfigMap(ctx) | ||
|
||
// then | ||
assert.Equal(t, wantError, gotError) | ||
assert.Equal(t, wantDomain, gotDomain) | ||
} | ||
|
||
func Test_domainMissingError(t *testing.T) { | ||
// given | ||
const errorMessage = "some error" | ||
err := fmt.Errorf(errorMessage) | ||
|
||
// when | ||
err0 := domainMissingError(nil) | ||
err1 := domainMissingError(err) | ||
|
||
// then | ||
assert.NotNil(t, err0) | ||
assert.NotNil(t, err1) | ||
assert.False(t, strings.Contains(strings.ToLower(err0.Error()), "nil")) | ||
assert.True(t, strings.Contains(err1.Error(), errorMessage)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.