|
4 | 4 | package mirrors
|
5 | 5 |
|
6 | 6 | import (
|
| 7 | + "fmt" |
7 | 8 | "testing"
|
8 | 9 |
|
9 | 10 | . "github.com/onsi/ginkgo/v2"
|
10 | 11 | "github.com/onsi/gomega"
|
11 | 12 | "github.com/stretchr/testify/assert"
|
| 13 | + "github.com/stretchr/testify/require" |
12 | 14 | corev1 "k8s.io/api/core/v1"
|
13 | 15 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
14 | 16 | "k8s.io/apimachinery/pkg/runtime"
|
@@ -499,6 +501,67 @@ func newMirrorSecretWithoutCA(name, namespace string) *corev1.Secret {
|
499 | 501 | }
|
500 | 502 | }
|
501 | 503 |
|
| 504 | +func Test_containerdConfigFromRegistryAddon(t *testing.T) { |
| 505 | + t.Parallel() |
| 506 | + tests := []struct { |
| 507 | + name string |
| 508 | + cluster *clusterv1.Cluster |
| 509 | + want containerdConfig |
| 510 | + wantErr error |
| 511 | + }{ |
| 512 | + { |
| 513 | + name: "valid input", |
| 514 | + cluster: &clusterv1.Cluster{ |
| 515 | + ObjectMeta: metav1.ObjectMeta{ |
| 516 | + Name: request.ClusterName, |
| 517 | + Namespace: request.Namespace, |
| 518 | + }, |
| 519 | + Spec: clusterv1.ClusterSpec{ |
| 520 | + ClusterNetwork: &clusterv1.ClusterNetwork{ |
| 521 | + Services: &clusterv1.NetworkRanges{ |
| 522 | + CIDRBlocks: []string{"192.168.0.1/16"}, |
| 523 | + }, |
| 524 | + }, |
| 525 | + }, |
| 526 | + }, |
| 527 | + want: containerdConfig{ |
| 528 | + URL: "http://192.168.0.20", |
| 529 | + Mirror: true, |
| 530 | + }, |
| 531 | + }, |
| 532 | + { |
| 533 | + name: "missing Services CIDR", |
| 534 | + cluster: &clusterv1.Cluster{ |
| 535 | + ObjectMeta: metav1.ObjectMeta{ |
| 536 | + Name: request.ClusterName, |
| 537 | + Namespace: request.Namespace, |
| 538 | + }, |
| 539 | + Spec: clusterv1.ClusterSpec{ |
| 540 | + ClusterNetwork: &clusterv1.ClusterNetwork{}, |
| 541 | + }, |
| 542 | + }, |
| 543 | + wantErr: fmt.Errorf( |
| 544 | + "error getting service IP for the registry addon: " + |
| 545 | + "error getting a service IP for a cluster: " + |
| 546 | + "unexpected empty service Subnets", |
| 547 | + ), |
| 548 | + }, |
| 549 | + } |
| 550 | + for idx := range tests { |
| 551 | + tt := tests[idx] |
| 552 | + t.Run(tt.name, func(t *testing.T) { |
| 553 | + t.Parallel() |
| 554 | + got, err := containerdConfigFromRegistryAddon(tt.cluster) |
| 555 | + if tt.wantErr != nil { |
| 556 | + require.EqualError(t, err, tt.wantErr.Error()) |
| 557 | + } else { |
| 558 | + require.NoError(t, err) |
| 559 | + } |
| 560 | + assert.Equal(t, tt.want, got) |
| 561 | + }) |
| 562 | + } |
| 563 | +} |
| 564 | + |
502 | 565 | func Test_needContainerdConfiguration(t *testing.T) {
|
503 | 566 | t.Parallel()
|
504 | 567 | tests := []struct {
|
|
0 commit comments