Skip to content

Commit 8eb1f74

Browse files
kartik-579Shubham9t9Shubham9t9prakarsh-dt
authored
feat: Kubectl proxy support (#355)
* added proxy url * set proxy url for terminal session get request * added logs * updated proxyUrl field case * updated proxy url field in cluster save/update apis * updated proxy url validation * wip * removed redundant logs * wip * wip * updated check in cluster save update apis for gitOps * feat: workflow to validate PRs if an issue is linked or not (#3730) * added github actions workflow to validate PRs if an issue is linked or not * Update pr-issue-validator.yaml * Update pr-issue-validator.yaml * Update pr-issue-validator.yaml --------- Co-authored-by: Shubham9t9 <[email protected]> Co-authored-by: Prakarsh <[email protected]> * commented out path-ignore section in pr-issue-validator (#3739) Co-authored-by: Shubham9t9 <[email protected]> * chore: Update pr-issue-validator.yaml (#3740) * Update pr-issue-validator.yaml * Update pr-issue-validator.yaml * Update pr-issue-validator.yaml * Update pr-issue-validator.yaml * Update pr-issue-validator.yaml * Update pr-issue-validator.yaml * Update pr-issue-validator.yaml * Update pr-issue-validator.yaml * Update pr-issue-validator.yaml * wip * updated informer obj * chore: migration for kubectl proxy (#3731) * added db scripts * updated sql script * updated sql script no. --------- Co-authored-by: Shubham Kumar <[email protected]> Co-authored-by: Shubham9t9 <[email protected]> Co-authored-by: Prakarsh <[email protected]>
1 parent bac9a59 commit 8eb1f74

File tree

15 files changed

+656
-532
lines changed

15 files changed

+656
-532
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Validate Pull Request
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
- edited
9+
- reopened
10+
branches:
11+
- 'main'
12+
- 'release-**'
13+
# paths-ignore:
14+
# - 'docs/**'
15+
# - '.github/'
16+
# - 'CHANGELOG/'
17+
# - 'charts/'
18+
# - 'manifests/'
19+
# - 'sample-docker-templates/'
20+
21+
jobs:
22+
validate-PR-issue:
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v2
28+
29+
- name: Validate Issue Reference
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GIT_TARGET_TOKEN }}
32+
PR_BODY: ${{ github.event.pull_request.body }}
33+
url: ${{ github.event.pull_request.url }}
34+
PRNUM: ${{ github.event.pull_request.number }}
35+
TITLE: ${{ github.event.pull_request.title }}
36+
run: |
37+
set -x
38+
if [[ "$TITLE" == *"doc:"* || "$TITLE" == *"docs:"* || "$TITLE" == *"chore:"* ]]; then
39+
echo "Skipping validation as this is a PR for documentation or chore."
40+
gh pr edit $PRNUM --remove-label "PR:Issue-verification-failed"
41+
gh pr edit $PRNUM --add-label "PR:Ready-to-Review"
42+
exit 0
43+
fi
44+
pattern="((Fixes|Resolves) #[0-9]+)"
45+
# Get the pull request body
46+
PR_BODY=$(jq -r '.pull_request.body' $GITHUB_EVENT_PATH)
47+
48+
issue_num=$(echo "$PR_BODY" | grep -o -P "$pattern" | head -n1 | grep -o -E "[0-9]+")
49+
if [[ -z "$issue_num" ]]; then
50+
issue_num="No issue number"
51+
fi
52+
echo "$issue_num"
53+
54+
IFS="/" read -r -a url_parts <<< "$url"
55+
56+
# Remove the last two elements (repos and the issue number)
57+
unset url_parts[-1]
58+
unset url_parts[-1]
59+
# Reattach the URL pieces
60+
url=$(IFS=/; echo "${url_parts[*]}")
61+
62+
# Add the issue number to the URL
63+
url="${url}/issues/${issue_num}"
64+
echo "$url"
65+
response_code=$(curl -s -o /dev/null -w "%{http_code}" "$url")
66+
if [[ "$response_code" -eq 200 ]]; then
67+
# Check if issue is open or closed
68+
text=$(curl -s "$url")
69+
echo "checking status of the issue"
70+
if [[ $(echo "$text" | jq -r '.state') == "open" ]]; then
71+
echo "Issue #$issue_num is open"
72+
echo "Issue reference found in the pull request body."
73+
gh pr edit $PRNUM --remove-label "PR:Issue-verification-failed"
74+
gh pr edit $PRNUM --add-label "PR:Ready-to-Review"
75+
exit 0
76+
else
77+
echo "Issue #$issue_num is not open"
78+
exit 1
79+
fi
80+
else
81+
echo "Invalid Response Code obtained - error code: $response_code"
82+
echo "No valid issue reference found in the pull request body."
83+
gh pr comment $PRNUM --body "PR is not linked to any issue, please make the corresponding changes in the body."
84+
gh pr edit $PRNUM --add-label "PR:Issue-verification-failed"
85+
gh pr edit $PRNUM --remove-label "PR:Ready-to-Review"
86+
exit 1
87+
fi

api/bean/ClusterInfo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ type ClusterInfo struct {
99
KeyData string `json:"keyData"`
1010
CertData string `json:"certData"`
1111
CAData string `json:"CAData"`
12+
ProxyUrl string `json:"proxyUrl"`
1213
}

api/helm-app/HelmAppService.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ func (impl *HelmAppServiceImpl) listApplications(ctx context.Context, clusterIds
148148
Token: clusterDetail.Config[k8s.BearerToken],
149149
ClusterId: int32(clusterDetail.Id),
150150
ClusterName: clusterDetail.ClusterName,
151+
ProxyUrl: clusterDetail.ProxyUrl,
151152
}
152153
req.Clusters = append(req.Clusters, config)
153154
}
@@ -282,6 +283,7 @@ func (impl *HelmAppServiceImpl) GetClusterConf(clusterId int) (*ClusterConfig, e
282283
Token: clusterObj.Config[k8s.BearerToken],
283284
ClusterId: int32(clusterObj.Id),
284285
ClusterName: clusterObj.ClusterName,
286+
ProxyUrl: clusterObj.ProxyUrl,
285287
}
286288
}
287289

api/helm-app/applist.pb.go

Lines changed: 532 additions & 523 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/helm-app/applist.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ message ClusterConfig {
99
string token = 2;
1010
int32 clusterId = 3;
1111
string clusterName = 4;
12+
string proxyUrl = 5;
1213
}
1314

1415
message AppListRequest {

client/telemetry/TelemetryEventClient.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ func (impl *TelemetryEventClientImpl) SummaryDetailsForTelemetry() (cluster []cl
226226
Token: clusterDetail.Config[k8s.BearerToken],
227227
ClusterId: int32(clusterDetail.Id),
228228
ClusterName: clusterDetail.ClusterName,
229+
ProxyUrl: clusterDetail.ProxyUrl,
229230
}
230231
req.Clusters = append(req.Clusters, config)
231232
applicationStream, err := impl.helmAppClient.ListApplication(context.Background(), req)

pkg/app/AppService.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3048,6 +3048,7 @@ func (impl *AppServiceImpl) createHelmAppForCdPipeline(overrideRequest *bean.Val
30483048
ClusterName: envOverride.Environment.Cluster.ClusterName,
30493049
Token: bearerToken,
30503050
ApiServerUrl: envOverride.Environment.Cluster.ServerUrl,
3051+
ProxyUrl: envOverride.Environment.Cluster.ProxyUrl,
30513052
},
30523053
}
30533054

pkg/cluster/ClusterService.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type ClusterBean struct {
6565
Id int `json:"id" validate:"number"`
6666
ClusterName string `json:"cluster_name,omitempty" validate:"required"`
6767
ServerUrl string `json:"server_url,omitempty" validate:"url,required"`
68+
ProxyUrl string `json:"proxyUrl,omitempty" validate:"omitempty,url"`
6869
PrometheusUrl string `json:"prometheus_url,omitempty" validate:"validate-non-empty-url"`
6970
Active bool `json:"active"`
7071
Config map[string]string `json:"config,omitempty"`
@@ -87,6 +88,7 @@ func GetClusterBean(model repository.Cluster) ClusterBean {
8788
bean.Id = model.Id
8889
bean.ClusterName = model.ClusterName
8990
bean.ServerUrl = model.ServerUrl
91+
bean.ProxyUrl = model.ProxyUrl
9092
bean.PrometheusUrl = model.PrometheusEndpoint
9193
bean.AgentInstallationStage = model.AgentInstallationStage
9294
bean.Active = model.Active
@@ -120,8 +122,9 @@ type PrometheusAuth struct {
120122
func (bean ClusterBean) GetClusterConfig() (*k8s.ClusterConfig, error) {
121123
host := bean.ServerUrl
122124
configMap := bean.Config
125+
proxyUrl := bean.ProxyUrl
123126
bearerToken := configMap[k8s.BearerToken]
124-
clusterCfg := &k8s.ClusterConfig{Host: host, BearerToken: bearerToken}
127+
clusterCfg := &k8s.ClusterConfig{Host: host, BearerToken: bearerToken, ProxyUrl: proxyUrl}
125128
clusterCfg.InsecureSkipTLSVerify = bean.InsecureSkipTLSVerify
126129
if bean.InsecureSkipTLSVerify == false {
127130
clusterCfg.KeyData = configMap[k8s.TlsKey]
@@ -226,7 +229,7 @@ func (impl *ClusterServiceImpl) ConvertClusterBeanToCluster(clusterBean *Cluster
226229
model.Config = clusterBean.Config
227230
model.PrometheusEndpoint = clusterBean.PrometheusUrl
228231
model.InsecureSkipTlsVerify = clusterBean.InsecureSkipTLSVerify
229-
232+
model.ProxyUrl = clusterBean.ProxyUrl
230233
if clusterBean.PrometheusAuth != nil {
231234
model.PUserName = clusterBean.PrometheusAuth.UserName
232235
model.PPassword = clusterBean.PrometheusAuth.Password
@@ -475,7 +478,9 @@ func (impl *ClusterServiceImpl) Update(ctx context.Context, bean *ClusterBean, u
475478
bean.Config[k8s.CertificateAuthorityData] = model.Config[k8s.CertificateAuthorityData]
476479
}
477480

478-
if bean.ServerUrl != model.ServerUrl || bean.InsecureSkipTLSVerify != model.InsecureSkipTlsVerify || dbConfigBearerToken != requestConfigBearerToken || dbConfigTlsKey != requestConfigTlsKey || dbConfigCertData != requestConfigCertData || dbConfigCAData != requestConfigCAData {
481+
if bean.ServerUrl != model.ServerUrl || bean.ProxyUrl != model.ProxyUrl ||
482+
bean.InsecureSkipTLSVerify != model.InsecureSkipTlsVerify || dbConfigBearerToken != requestConfigBearerToken ||
483+
dbConfigTlsKey != requestConfigTlsKey || dbConfigCertData != requestConfigCertData || dbConfigCAData != requestConfigCAData {
479484
if bean.ClusterName == DEFAULT_CLUSTER {
480485
impl.logger.Errorw("default_cluster is reserved by the system and cannot be updated, default_cluster", "name", bean.ClusterName)
481486
return nil, fmt.Errorf("default_cluster is reserved by the system and cannot be updated")
@@ -491,7 +496,7 @@ func (impl *ClusterServiceImpl) Update(ctx context.Context, bean *ClusterBean, u
491496
model.ServerUrl = bean.ServerUrl
492497
model.InsecureSkipTlsVerify = bean.InsecureSkipTLSVerify
493498
model.PrometheusEndpoint = bean.PrometheusUrl
494-
499+
model.ProxyUrl = bean.ProxyUrl
495500
if bean.PrometheusAuth != nil {
496501
if bean.PrometheusAuth.UserName != "" {
497502
model.PUserName = bean.PrometheusAuth.UserName
@@ -612,6 +617,7 @@ func (impl *ClusterServiceImpl) SyncNsInformer(bean *ClusterBean) {
612617
ClusterName: bean.ClusterName,
613618
BearerToken: requestConfig,
614619
ServerUrl: bean.ServerUrl,
620+
ProxyUrl: bean.ProxyUrl,
615621
InsecureSkipTLSVerify: bean.InsecureSkipTLSVerify,
616622
}
617623
if !bean.InsecureSkipTLSVerify {
@@ -668,6 +674,7 @@ func (impl *ClusterServiceImpl) buildInformer() {
668674
ClusterName: model.ClusterName,
669675
BearerToken: bearerToken,
670676
ServerUrl: model.ServerUrl,
677+
ProxyUrl: model.ProxyUrl,
671678
InsecureSkipTLSVerify: model.InsecureSkipTlsVerify,
672679
KeyData: model.Config[k8s.TlsKey],
673680
CertData: model.Config[k8s.CertData],
@@ -1023,6 +1030,7 @@ func (impl *ClusterServiceImpl) ValidateKubeconfig(kubeConfig string) (map[strin
10231030

10241031
if clusterObj != nil {
10251032
clusterBeanObject.InsecureSkipTLSVerify = clusterObj.InsecureSkipTLSVerify
1033+
clusterBeanObject.ProxyUrl = clusterObj.ProxyURL
10261034
}
10271035

10281036
if (clusterObj != nil) && !clusterObj.InsecureSkipTLSVerify && (clusterBeanObject.ErrorInConnecting == "") {

pkg/cluster/ClusterServiceExtended.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ func (impl *ClusterServiceImplExtended) Update(ctx context.Context, bean *Cluste
221221

222222
}
223223

224-
// if git-ops configured, then only update cluster in ACD, otherwise ignore
225-
if isGitOpsConfigured {
224+
// if git-ops configured and no proxy is configured, then only update cluster in ACD, otherwise ignore
225+
if isGitOpsConfigured && len(bean.ProxyUrl) == 0 {
226226
configMap := bean.Config
227227
serverUrl := bean.ServerUrl
228228
bearerToken := ""
@@ -334,8 +334,8 @@ func (impl *ClusterServiceImplExtended) Save(ctx context.Context, bean *ClusterB
334334
return nil, err
335335
}
336336

337-
// if git-ops configured, then only add cluster in ACD, otherwise ignore
338-
if isGitOpsConfigured {
337+
// if git-ops configured and no proxy is configured, then only add cluster in ACD, otherwise ignore
338+
if isGitOpsConfigured && len(clusterBean.ProxyUrl) == 0 {
339339
//create it into argo cd as well
340340
cl := impl.ConvertClusterBeanObjectToCluster(bean)
341341

pkg/cluster/repository/ClusterRepository.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type Cluster struct {
3535
Id int `sql:"id,pk"`
3636
ClusterName string `sql:"cluster_name"`
3737
ServerUrl string `sql:"server_url"`
38+
ProxyUrl string `sql:"proxy_url"`
3839
PrometheusEndpoint string `sql:"prometheus_endpoint"`
3940
Active bool `sql:"active,notnull"`
4041
CdArgoSetup bool `sql:"cd_argo_setup,notnull"`

0 commit comments

Comments
 (0)