Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solve controller start error when timeout in CloneOptionTrait is nil #1029

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions pkg/client/devops/jenkins/internal/bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,7 @@ func GetBitbucketServerSourceFromEtree(source *etree.Element) *devopsv1alpha3.Bi
}
}

if cloneTrait := traits.SelectElement(
"jenkins.plugins.git.traits.CloneOptionTrait"); cloneTrait != nil {
if cloneExtension := cloneTrait.SelectElement(
"extension"); cloneExtension != nil {
s.CloneOption = &devopsv1alpha3.GitCloneOption{}
if value, err := strconv.ParseBool(cloneExtension.SelectElement("shallow").Text()); err == nil {
s.CloneOption.Shallow = value
}
if value, err := strconv.ParseInt(cloneExtension.SelectElement("timeout").Text(), 10, 32); err == nil {
s.CloneOption.Timeout = int(value)
}
if value, err := strconv.ParseInt(cloneExtension.SelectElement("depth").Text(), 10, 32); err == nil {
s.CloneOption.Depth = int(value)
}
}
}
s.CloneOption = parseFromCloneTrait(traits.SelectElement("jenkins.plugins.git.traits.CloneOptionTrait"))

if regexTrait := traits.SelectElement(
"jenkins.scm.impl.trait.RegexSCMHeadFilterTrait"); regexTrait != nil {
Expand Down
19 changes: 3 additions & 16 deletions pkg/client/devops/jenkins/internal/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,9 @@ func GetGitSourcefromEtree(source *etree.Element) *devopsv1alpha3.GitSource {
"jenkins.plugins.git.traits.TagDiscoveryTrait"); tagDiscoverTrait != nil {
gitSource.DiscoverTags = true
}
if cloneTrait := traits.SelectElement(
"jenkins.plugins.git.traits.CloneOptionTrait"); cloneTrait != nil {
if cloneExtension := cloneTrait.SelectElement(
"extension"); cloneExtension != nil {
gitSource.CloneOption = &devopsv1alpha3.GitCloneOption{}
if value, err := strconv.ParseBool(cloneExtension.SelectElement("shallow").Text()); err == nil {
gitSource.CloneOption.Shallow = value
}
if value, err := strconv.ParseInt(cloneExtension.SelectElement("timeout").Text(), 10, 32); err == nil {
gitSource.CloneOption.Timeout = int(value)
}
if value, err := strconv.ParseInt(cloneExtension.SelectElement("depth").Text(), 10, 32); err == nil {
gitSource.CloneOption.Depth = int(value)
}
}
}

gitSource.CloneOption = parseFromCloneTrait(traits.SelectElement("jenkins.plugins.git.traits.CloneOptionTrait"))

if regexTrait := traits.SelectElement(
"jenkins.scm.impl.trait.RegexSCMHeadFilterTrait"); regexTrait != nil {
if regex := regexTrait.SelectElement("regex"); regex != nil {
Expand Down
18 changes: 2 additions & 16 deletions pkg/client/devops/jenkins/internal/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,8 @@ func GetGithubSourcefromEtree(source *etree.Element) *devopsv1alpha3.GithubSourc
klog.Warningf("invalid Gitlab discover PR trust value: %s", trust[1])
}
}
if cloneTrait := traits.SelectElement(
"jenkins.plugins.git.traits.CloneOptionTrait"); cloneTrait != nil {
if cloneExtension := cloneTrait.SelectElement(
"extension"); cloneExtension != nil {
githubSource.CloneOption = &devopsv1alpha3.GitCloneOption{}
if value, err := strconv.ParseBool(cloneExtension.SelectElement("shallow").Text()); err == nil {
githubSource.CloneOption.Shallow = value
}
if value, err := strconv.ParseInt(cloneExtension.SelectElement("timeout").Text(), 10, 32); err == nil {
githubSource.CloneOption.Timeout = int(value)
}
if value, err := strconv.ParseInt(cloneExtension.SelectElement("depth").Text(), 10, 32); err == nil {
githubSource.CloneOption.Depth = int(value)
}
}
}

githubSource.CloneOption = parseFromCloneTrait(traits.SelectElement("jenkins.plugins.git.traits.CloneOptionTrait"))

if regexTrait := traits.SelectElement(
"jenkins.scm.impl.trait.RegexSCMHeadFilterTrait"); regexTrait != nil {
Expand Down
22 changes: 2 additions & 20 deletions pkg/client/devops/jenkins/internal/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,8 @@ func GetGitlabSourceFromEtree(source *etree.Element) (gitSource *devopsv1alpha3.
klog.Warningf("invalid Gitlab discover PR trust value: %s", trust[1])
}
}
if cloneTrait := traits.SelectElement(
"jenkins.plugins.git.traits.CloneOptionTrait"); cloneTrait != nil {
if cloneExtension := cloneTrait.SelectElement(
"extension"); cloneExtension != nil {
gitSource.CloneOption = &devopsv1alpha3.GitCloneOption{}
if value, err := strconv.ParseBool(cloneExtension.SelectElement("shallow").Text()); err == nil {
gitSource.CloneOption.Shallow = value
}
if timeout := cloneExtension.SelectElement("timeout"); timeout != nil {
if value, err := strconv.ParseInt(timeout.Text(), 10, 32); err == nil {
gitSource.CloneOption.Timeout = int(value)
}
}
if depth := cloneExtension.SelectElement("depth"); depth != nil {
if value, err := strconv.ParseInt(depth.Text(), 10, 32); err == nil {
gitSource.CloneOption.Depth = int(value)
}
}
}
}

gitSource.CloneOption = parseFromCloneTrait(traits.SelectElement("jenkins.plugins.git.traits.CloneOptionTrait"))

if regexTrait := traits.SelectElement(
"jenkins.scm.impl.trait.RegexSCMHeadFilterTrait"); regexTrait != nil {
Expand Down
50 changes: 50 additions & 0 deletions pkg/client/devops/jenkins/internal/scm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright 2024 The KubeSphere Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package internal

import (
"github.com/beevik/etree"
devopsv1alpha3 "kubesphere.io/devops/pkg/api/devops/v1alpha3"
"strconv"
)

// common functions for all kinds of scm

func parseFromCloneTrait(cloneTrait *etree.Element) *devopsv1alpha3.GitCloneOption {
var cloneOption *devopsv1alpha3.GitCloneOption
if cloneTrait != nil {
if cloneExtension := cloneTrait.SelectElement("extension"); cloneExtension != nil {
cloneOption = &devopsv1alpha3.GitCloneOption{}
if shallow := cloneExtension.SelectElement("shallow"); shallow != nil {
if value, err := strconv.ParseBool(shallow.Text()); err == nil {
cloneOption.Shallow = value
}
}
if timeout := cloneExtension.SelectElement("timeout"); timeout != nil {
if value, err := strconv.ParseInt(timeout.Text(), 10, 32); err == nil {
cloneOption.Timeout = int(value)
}
}
if depth := cloneExtension.SelectElement("depth"); depth != nil {
if value, err := strconv.ParseInt(depth.Text(), 10, 32); err == nil {
cloneOption.Depth = int(value)
}
}
}
}
return cloneOption
}
2 changes: 1 addition & 1 deletion pkg/kapis/imagebuilder/v1alpha1/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

const LabelKeyLanguage = "language"
const LabelKeyLanguage = "language"

// apiHandlerOption holds some useful tools for API handler.
type apiHandlerOption struct {
Expand Down
Loading