Skip to content

Commit

Permalink
solve controller start error when timeout in CloneOptionTrait is nil (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yudong2015 authored Feb 27, 2024
1 parent 067e397 commit f0a23fe
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 69 deletions.
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

0 comments on commit f0a23fe

Please sign in to comment.