github.com/sealerio/sealer@v0.11.1-0.20240507115618-f4f89c5853ae/pkg/ipvs/ipvs_test.go (about)

     1  // Copyright © 2021 Alibaba Group Holding Ltd.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package ipvs
    16  
    17  import (
    18  	"testing"
    19  )
    20  
    21  var want = []string{
    22  	`apiVersion: v1
    23  kind: Pod
    24  metadata:
    25    creationTimestamp: null
    26    name: kube-lvscare
    27    namespace: kube-system
    28  spec:
    29    containers:
    30    - args:
    31      - care
    32      - --vs
    33      - 10.107.2.1:6443
    34      - --health-path
    35      - /healthz
    36      - --health-schem
    37      - https
    38      - --rs
    39      - 172.16.228.157:6443
    40      - --rs
    41      - 172.16.228.158:6443
    42      - --rs
    43      - 172.16.228.159:6443
    44      command:
    45      - /usr/bin/lvscare
    46      image: fdfadf
    47      imagePullPolicy: IfNotPresent
    48      name: main
    49      resources: {}
    50      securityContext:
    51        privileged: true
    52      volumeMounts:
    53      - mountPath: /lib/modules
    54        name: lib-modules
    55        readOnly: true
    56    hostNetwork: true
    57    volumes:
    58    - hostPath:
    59        path: /lib/modules
    60        type: ""
    61      name: lib-modules
    62  status: {}
    63  `,
    64  	`apiVersion: v1
    65  kind: Pod
    66  metadata:
    67    creationTimestamp: null
    68    name: kube-lvscare
    69    namespace: kube-system
    70  spec:
    71    containers:
    72    - args:
    73      - care
    74      - --vs
    75      - 10.107.2.1:6443
    76      - --health-path
    77      - /healthz
    78      - --health-schem
    79      - https
    80      - --rs
    81      - 172.16.228.157:6443
    82      command:
    83      - /usr/bin/lvscare
    84      image: fdfadf
    85      imagePullPolicy: IfNotPresent
    86      name: main
    87      resources: {}
    88      securityContext:
    89        privileged: true
    90      volumeMounts:
    91      - mountPath: /lib/modules
    92        name: lib-modules
    93        readOnly: true
    94    hostNetwork: true
    95    volumes:
    96    - hostPath:
    97        path: /lib/modules
    98        type: ""
    99      name: lib-modules
   100  status: {}
   101  `,
   102  	`apiVersion: v1
   103  kind: Pod
   104  metadata:
   105    creationTimestamp: null
   106    name: reg-lvscare
   107    namespace: kube-system
   108  spec:
   109    containers:
   110    - args:
   111      - care
   112      - --vs
   113      - 10.107.2.1:5000
   114      - --health-path
   115      - /healthz
   116      - --health-schem
   117      - https
   118      - --rs
   119      - 172.16.228.157:5000
   120      command:
   121      - /usr/bin/lvscare
   122      image: a1
   123      imagePullPolicy: IfNotPresent
   124      name: main
   125      resources: {}
   126      securityContext:
   127        privileged: true
   128      volumeMounts:
   129      - mountPath: /lib/modules
   130        name: lib-modules
   131        readOnly: true
   132    hostNetwork: true
   133    volumes:
   134    - hostPath:
   135        path: /lib/modules
   136        type: ""
   137      name: lib-modules
   138  status: {}
   139  `,
   140  }
   141  
   142  func TestLvsStaticPodYaml(t *testing.T) {
   143  	type args struct {
   144  		podName     string
   145  		vip         string
   146  		masters     []string
   147  		image       string
   148  		healthPath  string
   149  		healthSchem string
   150  	}
   151  	tests := []struct {
   152  		name string
   153  		args args
   154  		want string
   155  	}{
   156  		{
   157  			args: args{
   158  				podName: "kube-lvscare",
   159  				vip:     "10.107.2.1:6443",
   160  				masters: []string{
   161  					"172.16.228.157:6443",
   162  					"172.16.228.158:6443",
   163  					"172.16.228.159:6443",
   164  				},
   165  				image:       "fdfadf",
   166  				healthPath:  "/healthz",
   167  				healthSchem: "https",
   168  			},
   169  			want: want[0],
   170  		},
   171  		{
   172  			args: args{
   173  				podName:     "kube-lvscare",
   174  				vip:         "10.107.2.1:6443",
   175  				masters:     []string{"172.16.228.157:6443"},
   176  				image:       "fdfadf",
   177  				healthPath:  "/healthz",
   178  				healthSchem: "https",
   179  			},
   180  			want: want[1],
   181  		},
   182  		{
   183  			args: args{
   184  				podName:     "reg-lvscare",
   185  				vip:         "10.107.2.1:5000",
   186  				masters:     []string{"172.16.228.157:5000"},
   187  				image:       "a1",
   188  				healthPath:  "/healthz",
   189  				healthSchem: "https",
   190  			},
   191  			want: want[2],
   192  		},
   193  	}
   194  	for _, tt := range tests {
   195  		t.Run(tt.name, func(t *testing.T) {
   196  			if got, _ := LvsStaticPodYaml(tt.args.podName, tt.args.vip, tt.args.masters,
   197  				tt.args.image, tt.args.healthPath, tt.args.healthSchem); got != tt.want {
   198  				t.Errorf("LvsStaticPodYaml() = %v, want %v", got, tt.want)
   199  			}
   200  		})
   201  	}
   202  }