-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OCM-8285 | test: implement no-cni(cilium) supporting
- Loading branch information
1 parent
9cd807c
commit 0468497
Showing
7 changed files
with
251 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
apiVersion: cilium.io/v1alpha1 | ||
kind: CiliumConfig | ||
metadata: | ||
name: cilium | ||
namespace: cilium | ||
spec: | ||
debug: | ||
enabled: true | ||
k8s: | ||
requireIPv4PodCIDR: true | ||
logSystemLoad: true | ||
bpf: | ||
preallocateMaps: true | ||
etcd: | ||
leaseTTL: 30s | ||
ipv4: | ||
enabled: true | ||
ipv6: | ||
enabled: false | ||
identityChangeGracePeriod: 0s | ||
ipam: | ||
mode: "cluster-pool" | ||
operator: | ||
clusterPoolIPv4PodCIDRList: | ||
- "PODCIDR" | ||
clusterPoolIPv4MaskSize: "HOSTPREFIX" | ||
nativeRoutingCIDR: "PODCIDR" | ||
endpointRoutes: {enabled: true} | ||
clusterHealthPort: 9940 | ||
tunnelPort: 4789 | ||
cni: | ||
binPath: "/var/lib/cni/bin" | ||
confPath: "/var/run/multus/cni/net.d" | ||
chainingMode: portmap | ||
prometheus: | ||
serviceMonitor: {enabled: false} | ||
hubble: | ||
tls: {enabled: false} | ||
sessionAffinity: true |
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,84 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"path" | ||
"strings" | ||
"time" | ||
|
||
"github.com/openshift/rosa/tests/ci/config" | ||
"github.com/openshift/rosa/tests/utils/exec/occli" | ||
"github.com/openshift/rosa/tests/utils/log" | ||
) | ||
|
||
// DeployCilium The step is provided via here https://hypershift-docs.netlify.app/how-to/aws/other-sdn-providers/#cilium | ||
// Only for HCP cluster now | ||
func DeployCilium(ocClient *occli.Client, podCIDR string, hostPrefix string, outputDir string) error { | ||
ciliumVersion := "1.14.5" | ||
yamlFileNames := []string{ | ||
"cluster-network-03-cilium-ciliumconfigs-crd.yaml", | ||
"cluster-network-06-cilium-00000-cilium-namespace.yaml", | ||
"cluster-network-06-cilium-00001-cilium-olm-serviceaccount.yaml", | ||
"cluster-network-06-cilium-00002-cilium-olm-deployment.yaml", | ||
"cluster-network-06-cilium-00003-cilium-olm-service.yaml", | ||
"cluster-network-06-cilium-00004-cilium-olm-leader-election-role.yaml", | ||
"cluster-network-06-cilium-00005-cilium-olm-role.yaml", | ||
"cluster-network-06-cilium-00006-leader-election-rolebinding.yaml", | ||
"cluster-network-06-cilium-00007-cilium-olm-rolebinding.yaml", | ||
"cluster-network-06-cilium-00008-cilium-cilium-olm-clusterrole.yaml", | ||
"cluster-network-06-cilium-00009-cilium-cilium-clusterrole.yaml", | ||
"cluster-network-06-cilium-00010-cilium-cilium-olm-clusterrolebinding.yaml", | ||
"cluster-network-06-cilium-00011-cilium-cilium-clusterrolebinding.yaml", | ||
} | ||
|
||
url := "https://raw.githubusercontent.com/isovalent/olm-for-cilium/main/manifests" | ||
for _, n := range yamlFileNames { | ||
stdout, err := ocClient.Run( | ||
fmt.Sprintf("oc apply -f %s/cilium.v%s/%s", url, ciliumVersion, n)) | ||
time.Sleep(3 * time.Second) | ||
|
||
if err != nil { | ||
if strings.Contains(err.Error(), "Warning") { | ||
stdout, err = ocClient.Run( | ||
fmt.Sprintf("oc apply -f %s/cilium.v%s/%s", url, ciliumVersion, n)) | ||
} | ||
if err != nil { | ||
log.Logger.Errorf("%s:%s", stdout, err.Error()) | ||
return err | ||
} | ||
} | ||
} | ||
|
||
//Set PODCIDR/HOSTPREFIX in gobal var to replace in cilium.yml | ||
podCIDRReValue := podCIDR[:(len(podCIDR))-3] + "\\" + podCIDR[(len(podCIDR)-3):] | ||
|
||
//Use the right configuration for each network stack: data/resources/cilium.yaml | ||
var fileName string = path.Join(config.Test.ResourcesDir, "cilium.yaml") | ||
|
||
resultFile := path.Join(outputDir, "cilium.yaml") | ||
|
||
_, _, err := occli.RunCMD( | ||
fmt.Sprintf("cat %s | sed -e 's/HOSTPREFIX/%v/g' >> %s", fileName, hostPrefix, resultFile)) | ||
if err != nil { | ||
return err | ||
} | ||
_, _, err = occli.RunCMD( | ||
fmt.Sprintf("cat %s | sed -e 's/PODCIDR/%s/g' >> %s", resultFile, podCIDRReValue, resultFile)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
stdout, err := ocClient.Run(fmt.Sprintf("oc apply -f %s", resultFile)) | ||
time.Sleep(3 * time.Second) | ||
if err != nil { | ||
log.Logger.Errorf("%s", stdout) | ||
return err | ||
} | ||
|
||
return err | ||
} | ||
|
||
func GetKubeconfigDummyFunc() { | ||
// TODO: create IDP to get kubeconfig | ||
// Refer to OCM-9183 | ||
} |
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,66 @@ | ||
package occli | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
type Client struct { | ||
KubePath string | ||
} | ||
|
||
func NewOCClient(kubePath ...string) *Client { | ||
ocClient := &Client{} | ||
if len(kubePath) > 0 { | ||
ocClient = &Client{ | ||
KubePath: kubePath[0], | ||
} | ||
} else { | ||
DummyGetKubeConfigFromEnv() | ||
} | ||
return ocClient | ||
} | ||
|
||
type RunCMDError struct { | ||
Stderr string | ||
Err error | ||
CMD string | ||
} | ||
|
||
func (ocClient Client) Run(cmd string, pipeCommands ...string) (stdout string, err error) { | ||
|
||
var stderr string | ||
fmt.Println(">> Running CMD: ", cmd) | ||
var pipeCommand string | ||
for _, command := range pipeCommands { | ||
pipeCommand += fmt.Sprintf("|%s", command) | ||
} | ||
cmd = fmt.Sprintf("%s --kubeconfig %s %s", cmd, ocClient.KubePath, pipeCommand) | ||
stdout, stderr, err = RunCMD(cmd) | ||
if err != nil { | ||
t := &RunCMDError{Stderr: stderr, Err: err, CMD: cmd} | ||
err = t.Err | ||
} | ||
stdout = strings.TrimSuffix(stdout, "\n") | ||
fmt.Println(">> Got STDOUT: ", stdout) | ||
return | ||
} | ||
|
||
func RunCMD(cmd string) (stdout string, stderr string, err error) { | ||
var stdoutput bytes.Buffer | ||
var stderroutput bytes.Buffer | ||
CMD := exec.Command("bash", "-c", cmd) | ||
CMD.Stderr = &stderroutput | ||
CMD.Stdout = &stdoutput | ||
err = CMD.Run() | ||
stdout = strings.TrimPrefix(stdoutput.String(), "\n") | ||
stderr = strings.TrimPrefix(stderroutput.String(), "\n") | ||
return | ||
} | ||
|
||
func DummyGetKubeConfigFromEnv() { | ||
// login with oc cmd and then get the kubeconfig from ~/.kube/config | ||
// Refer to OCM-9183 | ||
} |
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