Skip to content

Commit f74a2df

Browse files
Added knative preparation script
Signed-off-by: Abhishek Kumar <abhishek22512@gmail.com>
1 parent 5f13fc7 commit f74a2df

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

tools/knative_preparation.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import subprocess
2+
import shutil
3+
4+
def run_command(command, check=True):
5+
try:
6+
subprocess.run(command, shell=True, check=check)
7+
except subprocess.CalledProcessError as e:
8+
print(f"Error occurred: {e}")
9+
exit(1)
10+
11+
def is_installed(command):
12+
return shutil.which(command) is not None
13+
14+
def install_minikube():
15+
if is_installed("minikube"):
16+
print("Minikube is already installed.")
17+
else:
18+
print("Installing Minikube...")
19+
run_command("curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64")
20+
run_command("sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64")
21+
22+
def install_kubectl():
23+
if is_installed("kubectl"):
24+
print("kubectl is already installed.")
25+
else:
26+
print("Installing kubectl...")
27+
run_command('curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"')
28+
run_command('curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"')
29+
run_command('echo "$(cat kubectl.sha256) kubectl" | sha256sum --check')
30+
run_command("sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl")
31+
32+
def install_cosign():
33+
if is_installed("cosign"):
34+
print("Cosign is already installed.")
35+
else:
36+
print("Installing Cosign...")
37+
run_command('curl -O -L "https://github.com/sigstore/cosign/releases/latest/download/cosign-linux-amd64"')
38+
run_command('sudo mv cosign-linux-amd64 /usr/local/bin/cosign')
39+
run_command('sudo chmod +x /usr/local/bin/cosign')
40+
41+
def install_jq():
42+
if is_installed("jq"):
43+
print("jq is already installed.")
44+
else:
45+
print("Installing jq...")
46+
run_command('sudo apt-get update && sudo apt-get install -y jq')
47+
48+
def install_knative():
49+
print("Extracting images from the manifest and verifying signatures...")
50+
run_command(
51+
'curl -sSL https://github.com/knative/serving/releases/download/knative-v1.14.1/serving-core.yaml '
52+
'| grep "gcr.io/" | awk \'{print $2}\' | sort | uniq '
53+
'| xargs -n 1 cosign verify -o text '
54+
'--certificate-identity=signer@knative-releases.iam.gserviceaccount.com '
55+
'--certificate-oidc-issuer=https://accounts.google.com'
56+
)
57+
58+
print("Installing Knative Serving component...")
59+
run_command('kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.14.1/serving-crds.yaml')
60+
run_command('kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.14.1/serving-core.yaml')
61+
62+
print("Installing Knative Kourier networking layer...")
63+
run_command('kubectl apply -f https://github.com/knative/net-kourier/releases/download/knative-v1.14.0/kourier.yaml')
64+
run_command('kubectl patch configmap/config-network '
65+
'--namespace knative-serving '
66+
'--type merge '
67+
'--patch \'{"data":{"ingress-class":"kourier.ingress.networking.knative.dev"}}\'')
68+
69+
print("Fetching External IP address or CNAME...")
70+
run_command('kubectl --namespace kourier-system get service kourier')
71+
72+
print("Verifying Knative Serving installation...")
73+
run_command('kubectl get pods -n knative-serving')
74+
75+
def main():
76+
install_minikube()
77+
install_kubectl()
78+
install_cosign()
79+
install_jq()
80+
install_knative()
81+
82+
if __name__ == "__main__":
83+
main()

0 commit comments

Comments
 (0)