From 6f9f0a8b487cb4a30c14f00d5d9ee50807c5bb2d Mon Sep 17 00:00:00 2001 From: Manabu McCloskey Date: Sun, 7 Jan 2024 17:56:19 -0800 Subject: [PATCH] remove git server (#117) Signed-off-by: Manabu Mccloskey --- README.md | 3 +- api/v1alpha1/gitserver_types.go | 48 --- api/v1alpha1/groupversion_info.go | 1 - api/v1alpha1/zz_generated.deepcopy.go | 105 ------- go.mod | 2 +- go.sum | 16 + pkg/apps/Dockerfile | 26 -- pkg/apps/README.md | 0 pkg/apps/entrypoint.sh | 85 ------ pkg/apps/fastcgi_params | 21 -- pkg/apps/image.go | 109 ------- pkg/apps/image_test.go | 1 - pkg/apps/nginx.conf | 55 ---- pkg/apps/resources.go | 31 -- pkg/apps/resources_test.go | 1 - pkg/apps/srv/backstage/install.yaml | 212 ------------- pkg/apps/srv/crossplane/crossplane.yaml | 22 -- pkg/cmd/gitserver/create/root.go | 150 ---------- pkg/cmd/gitserver/root.go | 26 -- pkg/cmd/root.go | 2 - pkg/controllers/gitserver/controller.go | 283 ------------------ pkg/controllers/gitserver/controller_test.go | 148 --------- pkg/controllers/gitserver/image.go | 65 ---- pkg/controllers/gitserver/image_test.go | 121 -------- pkg/controllers/localbuild/controller.go | 181 +---------- .../idpbuilder.cnoe.io_gitservers.yaml | 70 ----- pkg/kind/cluster.go | 14 +- pkg/kind/cluster_test.go | 8 - pkg/kind/registry.go | 114 ------- pkg/kind/registry_test.go | 70 ----- pkg/kind/resources/kind.yaml | 4 - 31 files changed, 26 insertions(+), 1968 deletions(-) delete mode 100644 api/v1alpha1/gitserver_types.go delete mode 100644 pkg/apps/Dockerfile delete mode 100644 pkg/apps/README.md delete mode 100755 pkg/apps/entrypoint.sh delete mode 100644 pkg/apps/fastcgi_params delete mode 100644 pkg/apps/image.go delete mode 100644 pkg/apps/image_test.go delete mode 100644 pkg/apps/nginx.conf delete mode 100644 pkg/apps/resources.go delete mode 100644 pkg/apps/resources_test.go delete mode 100644 pkg/apps/srv/backstage/install.yaml delete mode 100644 pkg/apps/srv/crossplane/crossplane.yaml delete mode 100644 pkg/cmd/gitserver/create/root.go delete mode 100644 pkg/cmd/gitserver/root.go delete mode 100644 pkg/controllers/gitserver/controller.go delete mode 100644 pkg/controllers/gitserver/controller_test.go delete mode 100644 pkg/controllers/gitserver/image.go delete mode 100644 pkg/controllers/gitserver/image_test.go delete mode 100644 pkg/controllers/resources/idpbuilder.cnoe.io_gitservers.yaml delete mode 100644 pkg/kind/registry.go delete mode 100644 pkg/kind/registry_test.go diff --git a/README.md b/README.md index dc5db9ba..86f2b197 100644 --- a/README.md +++ b/README.md @@ -259,4 +259,5 @@ This script runs kustomize to modify the basic installation manifests provided b ## Extending the IDP builder -We are actively working to include more patterns and examples of extending idpbuilder to get started easily. \ No newline at end of file +We are actively working to include more patterns and examples of extending idpbuilder to get started easily. + diff --git a/api/v1alpha1/gitserver_types.go b/api/v1alpha1/gitserver_types.go deleted file mode 100644 index e712fb66..00000000 --- a/api/v1alpha1/gitserver_types.go +++ /dev/null @@ -1,48 +0,0 @@ -package v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -type GitServerSource struct { - // Emedded enables the image containing the go binary embedded contents - Embedded bool `json:"embedded,omitempty"` - - // Image specifies a docker image to use. Specifying this disables installation of embedded applications. - Image string `json:"image,omitempty"` -} - -type GitServerSpec struct { - Source GitServerSource `json:"source,omitempty"` -} - -type GitServerStatus struct { - // ObservedGeneration is the 'Generation' of the Service that was last processed by the controller. - // +optional - ObservedGeneration int64 `json:"observedGeneration,omitempty"` - - // ImageID is the id of the most recently generated docker image or empty if no image has been created - ImageID string `json:"imageID,omitempty"` - - // Host is the host value of the ingress rule - Host string `json:"host,omitempty"` - - DeploymentAvailable bool `json:"deploymentAvailable"` -} - -// +kubebuilder:object:root=true -// +kubebuilder:subresource:status -type GitServer struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec GitServerSpec `json:"spec,omitempty"` - Status GitServerStatus `json:"status,omitempty"` -} - -// +kubebuilder:object:root=true -type GitServerList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []GitServer `json:"items"` -} diff --git a/api/v1alpha1/groupversion_info.go b/api/v1alpha1/groupversion_info.go index 888923e9..63ca9103 100644 --- a/api/v1alpha1/groupversion_info.go +++ b/api/v1alpha1/groupversion_info.go @@ -20,7 +20,6 @@ var ( func init() { SchemeBuilder.Register(&Localbuild{}, &LocalbuildList{}) - SchemeBuilder.Register(&GitServer{}, &GitServerList{}) SchemeBuilder.Register(&GitRepository{}, &GitRepositoryList{}) SchemeBuilder.Register(&CustomPackage{}, &CustomPackageList{}) } diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index fa74b221..ccafd57e 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -318,111 +318,6 @@ func (in *GitRepositoryStatus) DeepCopy() *GitRepositoryStatus { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *GitServer) DeepCopyInto(out *GitServer) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitServer. -func (in *GitServer) DeepCopy() *GitServer { - if in == nil { - return nil - } - out := new(GitServer) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *GitServer) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *GitServerList) DeepCopyInto(out *GitServerList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]GitServer, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitServerList. -func (in *GitServerList) DeepCopy() *GitServerList { - if in == nil { - return nil - } - out := new(GitServerList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *GitServerList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *GitServerSource) DeepCopyInto(out *GitServerSource) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitServerSource. -func (in *GitServerSource) DeepCopy() *GitServerSource { - if in == nil { - return nil - } - out := new(GitServerSource) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *GitServerSpec) DeepCopyInto(out *GitServerSpec) { - *out = *in - out.Source = in.Source -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitServerSpec. -func (in *GitServerSpec) DeepCopy() *GitServerSpec { - if in == nil { - return nil - } - out := new(GitServerSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *GitServerStatus) DeepCopyInto(out *GitServerStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitServerStatus. -func (in *GitServerStatus) DeepCopy() *GitServerStatus { - if in == nil { - return nil - } - out := new(GitServerStatus) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *GiteaStatus) DeepCopyInto(out *GiteaStatus) { *out = *in diff --git a/go.mod b/go.mod index ba2ca3de..77a8b6a1 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( code.gitea.io/sdk/gitea v0.16.0 github.com/argoproj/argo-cd/v2 v2.8.3 github.com/docker/docker v24.0.6+incompatible - github.com/docker/go-connections v0.4.0 github.com/go-git/go-git/v5 v5.10.0 github.com/google/go-cmp v0.5.9 github.com/spf13/cobra v1.7.0 @@ -46,6 +45,7 @@ require ( github.com/davidmz/go-pageant v1.0.2 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/docker/distribution v2.8.2+incompatible // indirect + github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/emicklei/go-restful/v3 v3.10.1 // indirect github.com/emirpasic/gods v1.18.1 // indirect diff --git a/go.sum b/go.sum index 69833dbb..2dc4f210 100644 --- a/go.sum +++ b/go.sum @@ -50,6 +50,7 @@ dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= dmitri.shuralyov.com/gpu/mtl v0.0.0-20201218220906-28db891af037/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU= +github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= github.com/Azure/azure-sdk-for-go v55.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= @@ -79,6 +80,7 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/Microsoft/hcsshim v0.8.22/go.mod h1:91uVCVzvX2QD16sMCenoxxXo6L1wJnLMX2PSufFMtF0= github.com/Microsoft/hcsshim v0.10.0-rc.8 h1:YSZVvlIIDD1UxQpJp0h+dnpLUw+TrY0cx8obKsp3bek= +github.com/Microsoft/hcsshim v0.10.0-rc.8/go.mod h1:OEthFdQv/AD2RAdzR6Mm1N1KPCztGKDurW1Z8b8VGMM= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= @@ -98,8 +100,11 @@ github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk5 github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0= github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a h1:HbKu58rmZpUGpz5+4FfNmIU+FmZg2P3Xaj2v2bfNWmk= +github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGnFV6hVsYE877CKEZ6tDNTjaSXYUk6QqoIK6PrAtcc= github.com/alicebob/miniredis/v2 v2.30.3 h1:hrqDB4cHFSHQf4gO3xu6YKQg8PqJpNjLYsQAFYHstqw= +github.com/alicebob/miniredis/v2 v2.30.3/go.mod h1:b25qWj4fCEsBeAAR2mlb0ufImGC6uH3VlUfb/HS5zKg= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= +github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210826220005-b48c857c3a0e/go.mod h1:F7bn7fEU90QkQ3tnmaTx3LTKLEDqnwWODIYppRQ5hnY= github.com/argoproj/argo-cd/v2 v2.8.3 h1:ybJ7eNoP7/u5Vqncais6WeVRBEGmZmriAIwLEKmWHIA= @@ -139,7 +144,9 @@ github.com/bombsimon/logrusr/v2 v2.0.1/go.mod h1:ByVAX+vHdLGAfdroiMg6q0zgq2FODY2 github.com/bradleyfalzon/ghinstallation/v2 v2.5.0 h1:yaYcGQ7yEIGbsJfW/9z7v1sLiZg/5rSNNXwmMct5XaE= github.com/bradleyfalzon/ghinstallation/v2 v2.5.0/go.mod h1:amcvPQMrRkWNdueWOjPytGL25xQGzox7425qMgzo+Vo= github.com/bsm/ginkgo/v2 v2.7.0 h1:ItPMPH90RbmZJt5GtkcNvIRuGEdwlBItdNVoyzaNQao= +github.com/bsm/ginkgo/v2 v2.7.0/go.mod h1:AiKlXPm7ItEHNc/2+OkrNG4E0ITzojb9/xWzvQ9XZ9w= github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y= +github.com/bsm/gomega v1.26.0/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= @@ -236,6 +243,7 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU= +github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM= github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= github.com/emicklei/go-restful/v3 v3.10.1 h1:rc42Y5YTp7Am7CS630D7JmhRjq4UlEUuEKfrDac4bSQ= @@ -281,6 +289,7 @@ github.com/getkin/kin-openapi v0.76.0/go.mod h1:660oXbgy5JFMKreazJaQTw7o+X00qeSy github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY= +github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= @@ -291,6 +300,7 @@ github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmS github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4= +github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII= github.com/go-git/go-git/v5 v5.10.0 h1:F0x3xXrAWmhwtzoCokU4IMPcBdncG+HAAqi9FcOOjbQ= github.com/go-git/go-git/v5 v5.10.0/go.mod h1:1FOZ/pQnqw24ghP2n7cunVl0ON55BsjPYvhWHvZGhoo= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= @@ -518,6 +528,7 @@ github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -630,6 +641,7 @@ github.com/onsi/gomega v1.24.0/go.mod h1:Z/NWtiqwBrwUt4/2loMmHL63EDLnYHmVbuBpDr2 github.com/onsi/gomega v1.24.1/go.mod h1:3AOiACssS3/MajrniINInwbfOOtfZvplPzuRSmvt1jM= github.com/onsi/gomega v1.25.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= +github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= @@ -708,6 +720,7 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rubiojr/go-vhd v0.0.0-20200706105327-02e210299021/go.mod h1:DM5xW0nvfNNm2uytzsvhI3OnX8uzaRAg8UX/CnDqbto= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= @@ -814,6 +827,7 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1 github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/gopher-lua v1.1.0 h1:BojcDhfyDWgU2f2TOzYK/g5p2gxMrku8oupLDqlnSqE= +github.com/yuin/gopher-lua v1.1.0/go.mod h1:GBR0iDaNXjAgGg9zfCvksxSRnQx76gclCIb7kdAd1Pw= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4= go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= @@ -854,6 +868,7 @@ go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= +go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= @@ -1388,6 +1403,7 @@ gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI= +gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/warnings.v0 v0.1.1/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= diff --git a/pkg/apps/Dockerfile b/pkg/apps/Dockerfile deleted file mode 100644 index 0528b773..00000000 --- a/pkg/apps/Dockerfile +++ /dev/null @@ -1,26 +0,0 @@ -FROM nginx:stable - -RUN set -x && \ - apt-get -y update && \ - apt-get install -y git fcgiwrap spawn-fcgi wget && \ - - adduser git --home /var/lib/git && \ - adduser nginx git && \ - - git config --system http.receivepack true && \ - git config --system http.uploadpack true && \ - git config --system user.email "gitserver@git.com" && \ - git config --system user.name "Git Server" && \ - - ln -sf /dev/stdout /var/log/nginx/access.log && \ - ln -sf /dev/stderr /var/log/nginx/error.log - - -ADD nginx.conf /etc/nginx/nginx.conf -ADD ./entrypoint.sh /usr/local/bin/entrypoint -RUN chmod 755 /usr/local/bin/entrypoint - -ENTRYPOINT [ "/usr/local/bin/entrypoint" ] -CMD [ "-start" ] - -COPY srv /var/lib/initial/idpbuilder-resources diff --git a/pkg/apps/README.md b/pkg/apps/README.md deleted file mode 100644 index e69de29b..00000000 diff --git a/pkg/apps/entrypoint.sh b/pkg/apps/entrypoint.sh deleted file mode 100755 index 619f72f9..00000000 --- a/pkg/apps/entrypoint.sh +++ /dev/null @@ -1,85 +0,0 @@ -#!/bin/bash - -# Based off of https://github.com/cirocosta/gitserver-http/blob/master/entrypoint.sh - -# Initializes Nginx and the git cgi scripts -# for git http-backend through fcgiwrap. -# -# Usage: -# entrypoint -# -# Commands: -# -start starts the git server (nginx + fcgi) -# -# -init turns directories under `/var/lib/initial` -# into bare repositories at `/var/lib/git` -# - -set -o errexit - -readonly GIT_PROJECT_ROOT="/var/lib/git" -readonly GIT_INITIAL_ROOT="/var/lib/initial" -readonly GIT_HTTP_EXPORT_ALL="true" -readonly GIT_USER="git" -readonly GIT_GROUP="git" - -readonly FCGIPROGRAM="/usr/sbin/fcgiwrap" -readonly USERID="nginx" -readonly SOCKUSERID="$USERID" -readonly FCGISOCKET="/var/run/fcgiwrap.socket" - -main() { - mkdir -p $GIT_PROJECT_ROOT - - # Checks if $GIT_INITIAL_ROOT has files - if [[ $(ls -A ${GIT_INITIAL_ROOT}) ]]; then - initialize_initial_repositories - fi - initialize_services -} - -initialize_services() { - # Check permissions on $GIT_PROJECT_ROOT - chown -R git:git $GIT_PROJECT_ROOT - chmod -R 775 $GIT_PROJECT_ROOT - - /usr/bin/spawn-fcgi \ - -s $FCGISOCKET \ - -F 4 \ - -u $USERID \ - -g $USERID \ - -U $USERID \ - -G $GIT_GROUP -- \ - "$FCGIPROGRAM" - exec nginx -} - -initialize_initial_repositories() { - cd $GIT_INITIAL_ROOT - for dir in $(find . -name "*" -type d -maxdepth 1 -mindepth 1); do - echo "Initializing repository $dir" - init_and_commit $dir - done -} - -init_and_commit() { - local dir=$1 - local tmp_dir=$(mktemp -d) - - cp -r $dir/* $tmp_dir - pushd . >/dev/null - cd $tmp_dir - - if [[ -d "./.git" ]]; then - rm -rf ./.git - fi - - git init &>/dev/null - git add --all . &>/dev/null - git commit -m "first commit" &>/dev/null - git clone --bare $tmp_dir $GIT_PROJECT_ROOT/${dir}.git &>/dev/null - - popd >/dev/null -} - -main "$@" \ No newline at end of file diff --git a/pkg/apps/fastcgi_params b/pkg/apps/fastcgi_params deleted file mode 100644 index 6000593e..00000000 --- a/pkg/apps/fastcgi_params +++ /dev/null @@ -1,21 +0,0 @@ -fastcgi_param QUERY_STRING $query_string; -fastcgi_param REQUEST_METHOD $request_method; -fastcgi_param CONTENT_TYPE $content_type; -fastcgi_param CONTENT_LENGTH $content_length; - -fastcgi_param SCRIPT_NAME $fastcgi_script_name; -fastcgi_param REQUEST_URI $request_uri; -fastcgi_param DOCUMENT_URI $document_uri; -fastcgi_param DOCUMENT_ROOT $document_root; -fastcgi_param SERVER_PROTOCOL $server_protocol; -fastcgi_param REQUEST_SCHEME $scheme; -fastcgi_param HTTPS $https if_not_empty; - -fastcgi_param GATEWAY_INTERFACE CGI/1.1; -fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; - -fastcgi_param REMOTE_ADDR $remote_addr; -fastcgi_param REMOTE_PORT $remote_port; -fastcgi_param SERVER_ADDR $server_addr; -fastcgi_param SERVER_PORT $server_port; -fastcgi_param SERVER_NAME $server_name; \ No newline at end of file diff --git a/pkg/apps/image.go b/pkg/apps/image.go deleted file mode 100644 index 9a5ab164..00000000 --- a/pkg/apps/image.go +++ /dev/null @@ -1,109 +0,0 @@ -package apps - -import ( - "bufio" - "context" - "encoding/json" - "fmt" - "io" - "io/fs" - "os" - "path/filepath" - - "github.com/cnoe-io/idpbuilder/globals" - "github.com/cnoe-io/idpbuilder/pkg/docker" - "github.com/cnoe-io/idpbuilder/pkg/util" - - "github.com/docker/docker/api/types" - registryTypes "github.com/docker/docker/api/types/registry" - dockerClient "github.com/docker/docker/client" - "sigs.k8s.io/controller-runtime/pkg/log" -) - -func PushImage(ctx context.Context, client *dockerClient.Client, tag string) (*string, error) { - log := log.FromContext(ctx) - - // Push docker image - log.Info("Pushing docker image", "tag", tag) - authConfig, err := registryTypes.EncodeAuthConfig(registryTypes.AuthConfig{}) - if err != nil { - return nil, err - } - resp, err := client.ImagePush(ctx, tag, types.ImagePushOptions{ - RegistryAuth: authConfig, - }) - if err != nil { - return nil, err - } - defer resp.Close() - - // Check for error in output - var pushErrorMessage docker.ErrorMessage - pushBuffIOReader := bufio.NewReader(resp) - - for { - streamBytes, err := pushBuffIOReader.ReadBytes('\n') - if err == io.EOF { - break - } - json.Unmarshal(streamBytes, &pushErrorMessage) - if pushErrorMessage.ErrorStr != "" { - return nil, pushErrorMessage - } - } - - di, err := client.DistributionInspect(ctx, tag, authConfig) - if err != nil { - return nil, err - } - - regImgId := di.Descriptor.Digest.String() - log.Info("Image Pushed", "digest", regImgId) - - return ®ImgId, nil -} - -func BuildAppsImage(ctx context.Context, client *dockerClient.Client, tags []string, labels map[string]string, appsFS fs.FS) (*string, error) { - log := log.FromContext(ctx) - - log.Info("Building docker image") - - // Create docker image dir and defer cleanup - workDir, err := os.MkdirTemp("", fmt.Sprintf("%s-dockerimage", globals.ProjectName)) - if err != nil { - return nil, err - } - defer os.RemoveAll(workDir) - - // Write base image to work dir - if err := util.CopyDir(GitServerFS, workDir); err != nil { - log.Error(err, "Copying base git server contents to work dir") - return nil, err - } - - // Write apps fs to workdir - srvWorkDir := filepath.Join(workDir, "srv") - if err = os.Mkdir(srvWorkDir, 0700); err != nil { - log.Error(err, "Creating srv dir for apps fs") - return nil, err - } - if err = util.WriteFS(appsFS, srvWorkDir); err != nil { - log.Error(err, "Writing apps fs to work dir") - return nil, err - } - - // Build docker image - auxMessage, err := docker.BuildDir(ctx, client, workDir, types.ImageBuildOptions{ - Tags: tags, - Labels: labels, - }) - if err != nil { - log.Error(err, "Building docker image") - return nil, err - } - if auxMessage == nil { - return nil, fmt.Errorf("docker image build failed") - } - - return &auxMessage.Aux.ID, nil -} diff --git a/pkg/apps/image_test.go b/pkg/apps/image_test.go deleted file mode 100644 index cff2ab90..00000000 --- a/pkg/apps/image_test.go +++ /dev/null @@ -1 +0,0 @@ -package apps diff --git a/pkg/apps/nginx.conf b/pkg/apps/nginx.conf deleted file mode 100644 index b26881d2..00000000 --- a/pkg/apps/nginx.conf +++ /dev/null @@ -1,55 +0,0 @@ -user nginx; -worker_processes 4; -pid /run/nginx.pid; - -events { - worker_connections 1024; -} - -http { - sendfile on; - tcp_nopush on; - tcp_nodelay on; - keepalive_timeout 65; - types_hash_max_size 2048; - - include /etc/nginx/mime.types; - default_type application/octet-stream; - - access_log /var/log/nginx/access.log; - error_log /var/log/nginx/error.log; - - gzip on; - gzip_disable "msie6"; - - server { - listen 80 default_server; - listen [::]:80 default_server; - - location /ping { - add_header Content-Type text/plain; - return 200 'pong'; - } - - location ~ ^.*\.git/objects/([0-9a-f]+/[0-9a-f]+|pack/pack-[0-9a-f]+.(pack|idx))$ { - root /var/lib/git; - } - - location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-(upload|receive)-pack)$ { - include fastcgi_params; - fastcgi_param DOCUMENT_ROOT /usr/lib/git-core; - fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; - fastcgi_param SCRIPT_NAME git-http-backend; - fastcgi_param GIT_HTTP_EXPORT_ALL ""; - fastcgi_param GIT_PROJECT_ROOT /var/lib/git; - fastcgi_param PATH_INFO $uri; - fastcgi_pass unix:/var/run/fcgiwrap.socket; - } - - location / { - try_files $uri $uri/ =404; - } - } -} - -daemon off; \ No newline at end of file diff --git a/pkg/apps/resources.go b/pkg/apps/resources.go deleted file mode 100644 index f5164fa5..00000000 --- a/pkg/apps/resources.go +++ /dev/null @@ -1,31 +0,0 @@ -package apps - -import ( - "embed" - "io/fs" -) - -type EmbedApp struct { - Name string - Path string -} - -var ( - //go:embed Dockerfile nginx.conf entrypoint.sh - GitServerFS embed.FS - - //go:embed srv/* - EmbeddedAppsFS embed.FS - - EmbedApps = []EmbedApp{{ - Name: "backstage", - Path: "backstage", - }, { - Name: "crossplane", - Path: "crossplane", - }} -) - -func GetAppsFS() (fs.FS, error) { - return fs.Sub(EmbeddedAppsFS, "srv") -} diff --git a/pkg/apps/resources_test.go b/pkg/apps/resources_test.go deleted file mode 100644 index cff2ab90..00000000 --- a/pkg/apps/resources_test.go +++ /dev/null @@ -1 +0,0 @@ -package apps diff --git a/pkg/apps/srv/backstage/install.yaml b/pkg/apps/srv/backstage/install.yaml deleted file mode 100644 index fb960b2d..00000000 --- a/pkg/apps/srv/backstage/install.yaml +++ /dev/null @@ -1,212 +0,0 @@ -apiVersion: v1 -kind: Namespace -metadata: - name: backstage ---- -apiVersion: v1 -kind: ServiceAccount -metadata: - name: backstage - namespace: backstage ---- -# For invoking Argo Workflows -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: backstage-argo-worfklows -rules: - - apiGroups: - - argoproj.io - resources: - - workflows - verbs: - - create ---- -# For displaying resources in Backstage -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: read-all -rules: - - apiGroups: - - '*' - resources: - - '*' - verbs: - - get - - list - - watch ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: backstage-argo-worfklows -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: backstage-argo-worfklows -subjects: - - kind: ServiceAccount - name: backstage - namespace: backstage ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: backstage-read-all -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: read-all -subjects: - - kind: ServiceAccount - name: backstage - namespace: backstage ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: backstage - namespace: backstage -spec: - replicas: 1 - selector: - matchLabels: - app: backstage - template: - metadata: - labels: - app: backstage - spec: - serviceAccountName: backstage - volumes: - - name: backstage-config - projected: - sources: - - configMap: - items: - - key: app-config.yaml - path: app-config.yaml - name: backstage-config - containers: - - name: backstage - command: - - node - - packages/backend - - --config - - config/app-config.yaml - image: public.ecr.aws/cnoe-io/backstage:v0.0.3 - imagePullPolicy: IfNotPresent - ports: - - name: backend - containerPort: 7007 - volumeMounts: - - mountPath: /app/config - name: backstage-config - readOnly: true ---- ---- -apiVersion: v1 -kind: Service -metadata: - name: backstage - namespace: backstage -spec: - ports: - - name: http-backend - port: 7007 - protocol: TCP - targetPort: backend - selector: - app: backstage - sessionAffinity: None - type: ClusterIP ---- -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: backstage - namespace: backstage -spec: - ingressClassName: nginx - rules: - - host: backstage.cnoe.localtest.me - http: - paths: - - backend: - service: - name: backstage - port: - number: 7007 - path: / - pathType: Prefix ---- -apiVersion: v1 -kind: ConfigMap -metadata: - labels: - app.kubernetes.io/name: backstage - name: backstage-config - namespace: backstage -data: - app-config.yaml: | - app: - title: CNOE - baseUrl: "https://backstage.cnoe.localtest.me:8443" - organization: - name: CNOE - backend: - baseUrl: "https://backstage.cnoe.localtest.me:8443" - listen: - port: 7007 - csp: - connect-src: ["'self'", 'http:', 'https:'] - cors: - origin: "https://backstage.cnoe.localtest.me:8443" - methods: [GET, HEAD, PATCH, POST, PUT, DELETE] - credentials: true - database: - client: better-sqlite3 - connection: ':memory:' - cache: - store: memory - integrations: {} - proxy: - techdocs: - builder: 'local' - generator: - runIn: 'docker' - publisher: - type: 'local' - auth: - environment: local - providers: {} - scaffolder: {} - catalog: - import: - entityFilename: catalog-info.yaml - pullRequestBranchName: backstage-integration - rules: - - allow: - - Component - - API - - Resource - - System - - Domain - - Location - locations: [] - kubernetes: - serviceLocatorMethod: - type: 'multiTenant' - clusterLocatorMethods: - - type: 'config' - clusters: - - url: https://kubernetes.default.svc.cluster.local - name: local - authProvider: 'serviceAccount' - skipTLSVerify: true - skipMetricsLookup: true - serviceAccountToken: - $file: /var/run/secrets/kubernetes.io/serviceaccount/token - caData: - $file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt diff --git a/pkg/apps/srv/crossplane/crossplane.yaml b/pkg/apps/srv/crossplane/crossplane.yaml deleted file mode 100644 index 825c6b0c..00000000 --- a/pkg/apps/srv/crossplane/crossplane.yaml +++ /dev/null @@ -1,22 +0,0 @@ -apiVersion: argoproj.io/v1alpha1 -kind: Application -metadata: - name: crossplane-helm - namespace: argocd -spec: - destination: - namespace: crossplane-system - server: "https://kubernetes.default.svc" - source: - chart: crossplane - repoURL: https://charts.crossplane.io/stable - targetRevision: 1.11.1 - helm: - releaseName: crossplane - project: default - syncPolicy: - automated: - prune: true - selfHeal: true - syncOptions: - - CreateNamespace=true \ No newline at end of file diff --git a/pkg/cmd/gitserver/create/root.go b/pkg/cmd/gitserver/create/root.go deleted file mode 100644 index 0a9258b6..00000000 --- a/pkg/cmd/gitserver/create/root.go +++ /dev/null @@ -1,150 +0,0 @@ -package create - -import ( - "context" - "flag" - "fmt" - "os" - "path/filepath" - - "github.com/cnoe-io/idpbuilder/api/v1alpha1" - "github.com/cnoe-io/idpbuilder/globals" - "github.com/cnoe-io/idpbuilder/pkg/apps" - "github.com/cnoe-io/idpbuilder/pkg/controllers" - "github.com/cnoe-io/idpbuilder/pkg/docker" - "github.com/cnoe-io/idpbuilder/pkg/k8s" - "github.com/cnoe-io/idpbuilder/pkg/kind" - "github.com/spf13/cobra" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/client-go/tools/clientcmd" - "k8s.io/client-go/util/homedir" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - "sigs.k8s.io/controller-runtime/pkg/log/zap" -) - -var ( - // Flags - buildName string - serverName string - sourcePath string - - setupLog = ctrl.Log.WithName("setup") -) - -var CreateCmd = &cobra.Command{ - Use: "create", - Short: "Create a GitServer", - Long: ``, - PreRunE: preCreate, - RunE: create, -} - -func init() { - CreateCmd.PersistentFlags().StringVar(&buildName, "build-name", "localdev", "Name for build (Prefix for kind cluster name, pod names, etc)") - CreateCmd.PersistentFlags().StringVar(&serverName, "server-name", "", "Name of gitserver, must be unique within a build (name)") - CreateCmd.PersistentFlags().StringVar(&sourcePath, "source", "", "Path to directory to use as gitserver source") - - zapfs := flag.NewFlagSet("zap", flag.ExitOnError) - opts := zap.Options{ - Development: true, - } - opts.BindFlags(zapfs) - CreateCmd.Flags().AddGoFlagSet(zapfs) - - ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) -} - -func preCreate(cmd *cobra.Command, args []string) error { - if sourcePath == "" { - return fmt.Errorf("source argument required") - } - if serverName == "" { - return fmt.Errorf("serverName argument required") - } - return nil -} - -func create(cmd *cobra.Command, args []string) error { - ctx, ctxCancel := context.WithCancel(ctrl.SetupSignalHandler()) - defer ctxCancel() - - // Build a docker client - dockerClient, err := docker.GetDockerClient() - if err != nil { - return err - } - defer dockerClient.Close() - - // Build a kube client - scheme := k8s.GetScheme() - kubeConfigPath := filepath.Join(homedir.HomeDir(), ".kube", "config") - kubeConfig, err := clientcmd.BuildConfigFromFlags("", kubeConfigPath) - if err != nil { - setupLog.Error(err, "Building kubeconfig from kind cluster") - return err - } - kubeClient, err := client.New(kubeConfig, client.Options{Scheme: scheme}) - if err != nil { - setupLog.Error(err, "Creating kubernetes client") - return err - } - - // Create controller manager - mgr, err := ctrl.NewManager(kubeConfig, ctrl.Options{ - Scheme: scheme, - }) - if err != nil { - setupLog.Error(err, "Creating controller manager") - return err - } - - // Run controllers - managerExit := make(chan error) - if err := controllers.RunControllers(ctx, mgr, managerExit, ctxCancel, true); err != nil { - setupLog.Error(err, "Running controllers") - return err - } - - // Build and push image - srcFS := os.DirFS(sourcePath) - imageTag := fmt.Sprintf("localhost:%d/%s-%s-%s", kind.ExposedRegistryPort, globals.ProjectName, buildName, serverName) - imageID, err := apps.BuildAppsImage(ctx, dockerClient, []string{imageTag}, map[string]string{}, srcFS) - if err != nil { - return err - } - if imageID == nil { - return fmt.Errorf("failed to get image id after build") - } - - regImgId, err := apps.PushImage(ctx, dockerClient, imageTag) - if err != nil { - return err - } - if regImgId == nil { - return fmt.Errorf("failed to get registry image id after push") - } - - // Create GitServer k8s resource - gitServer := v1alpha1.GitServer{ - ObjectMeta: metav1.ObjectMeta{ - Name: serverName, - Namespace: globals.GetProjectNamespace(buildName), - }, - } - if _, err := controllerutil.CreateOrUpdate(ctx, kubeClient, &gitServer, func() error { - gitServer.Spec = v1alpha1.GitServerSpec{ - Source: v1alpha1.GitServerSource{ - Image: fmt.Sprintf("%s@%s", imageTag, *regImgId), - }, - } - return nil - }); err != nil { - return err - } - - err = <-managerExit - close(managerExit) - return err -} diff --git a/pkg/cmd/gitserver/root.go b/pkg/cmd/gitserver/root.go deleted file mode 100644 index 92734b08..00000000 --- a/pkg/cmd/gitserver/root.go +++ /dev/null @@ -1,26 +0,0 @@ -package gitserver - -import ( - "fmt" - "os" - - "github.com/cnoe-io/idpbuilder/pkg/cmd/gitserver/create" - "github.com/spf13/cobra" -) - -var GitServerCmd = &cobra.Command{ - Use: "gitserver", - Short: "Interact with GitServers", - Long: "", -} - -func init() { - GitServerCmd.AddCommand(create.CreateCmd) -} - -func Execute() { - if err := GitServerCmd.Execute(); err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } -} diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go index f8855537..7b29133e 100644 --- a/pkg/cmd/root.go +++ b/pkg/cmd/root.go @@ -5,7 +5,6 @@ import ( "os" "github.com/cnoe-io/idpbuilder/pkg/cmd/create" - "github.com/cnoe-io/idpbuilder/pkg/cmd/gitserver" "github.com/spf13/cobra" ) @@ -17,7 +16,6 @@ var rootCmd = &cobra.Command{ func init() { rootCmd.AddCommand(create.CreateCmd) - rootCmd.AddCommand(gitserver.GitServerCmd) } func Execute() { diff --git a/pkg/controllers/gitserver/controller.go b/pkg/controllers/gitserver/controller.go deleted file mode 100644 index b4e2e08a..00000000 --- a/pkg/controllers/gitserver/controller.go +++ /dev/null @@ -1,283 +0,0 @@ -package gitserver - -import ( - "context" - "fmt" - "io/fs" - "time" - - "github.com/cnoe-io/idpbuilder/api/v1alpha1" - "github.com/cnoe-io/idpbuilder/globals" - appsv1 "k8s.io/api/apps/v1" - v1 "k8s.io/api/core/v1" - networkingv1 "k8s.io/api/networking/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/intstr" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - "sigs.k8s.io/controller-runtime/pkg/log" -) - -const ( - gitServerDeploymentContainerName string = "httpd" - gitServerIngressHostnameBase string = ".cnoe.localtest.me" - repoUrlFmt string = "http://%s.%s.svc/idpbuilder-resources.git" -) - -func getRepoUrl(resource *v1alpha1.GitServer) string { - return fmt.Sprintf(repoUrlFmt, managedResourceName(resource), resource.Namespace) -} - -var gitServerLabelKey string = fmt.Sprintf("%s-gitserver", globals.ProjectName) - -func ingressHostname(resource *v1alpha1.GitServer) string { - return fmt.Sprintf("%s%s", resource.Name, gitServerIngressHostnameBase) -} - -func managedResourceName(resource *v1alpha1.GitServer) string { - return fmt.Sprintf("%s-%s", globals.GitServerResourcename(), resource.Name) -} - -type subReconciler func(ctx context.Context, req ctrl.Request, resource *v1alpha1.GitServer) (ctrl.Result, error) - -type GitServerReconciler struct { - client.Client - Scheme *runtime.Scheme - Content fs.FS -} - -func GetGitServerLabels(resource *v1alpha1.GitServer) map[string]string { - return map[string]string{ - "app": fmt.Sprintf("%s-%s", globals.ProjectName, resource.Name), - } -} - -func SetGitDeploymentPodTemplateSpec(resource *v1alpha1.GitServer, target *appsv1.Deployment) { - target.Spec.Template = v1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Labels: GetGitServerLabels(resource), - }, - Spec: v1.PodSpec{ - Containers: []v1.Container{{ - Name: gitServerDeploymentContainerName, - Image: GetImageUrl(resource), - Ports: []v1.ContainerPort{{ - Name: "http", - ContainerPort: 80, - }}, - ReadinessProbe: &v1.Probe{ - ProbeHandler: v1.ProbeHandler{ - HTTPGet: &v1.HTTPGetAction{ - Path: "idpbuilder-resources.git/HEAD", - Port: intstr.FromInt(80), - }, - }, - }, - }}, - }, - } -} - -func SetIngressSpec(resource *v1alpha1.GitServer, ingress *networkingv1.Ingress) { - ingressName := "nginx" - pathType := networkingv1.PathTypePrefix - - ingress.Spec = networkingv1.IngressSpec{ - IngressClassName: &ingressName, - Rules: []networkingv1.IngressRule{{ - Host: ingressHostname(resource), - IngressRuleValue: networkingv1.IngressRuleValue{ - HTTP: &networkingv1.HTTPIngressRuleValue{ - Paths: []networkingv1.HTTPIngressPath{{ - Path: "/", - PathType: &pathType, - Backend: networkingv1.IngressBackend{ - Service: &networkingv1.IngressServiceBackend{ - Name: managedResourceName(resource), - Port: networkingv1.ServiceBackendPort{ - Name: "http", - }, - }, - }, - }}, - }, - }, - }}, - } -} - -func SetServiceSpec(resource *v1alpha1.GitServer, service *v1.Service) { - service.Spec = v1.ServiceSpec{ - Selector: GetGitServerLabels(resource), - Ports: []v1.ServicePort{{ - Name: "http", - Protocol: v1.ProtocolTCP, - Port: 80, - TargetPort: intstr.FromString("http"), - }}, - } -} - -func (g *GitServerReconciler) reconcileDeployment(ctx context.Context, req ctrl.Request, resource *v1alpha1.GitServer) (ctrl.Result, error) { - log := log.FromContext(ctx) - - deployment := &appsv1.Deployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: managedResourceName(resource), - Namespace: resource.Namespace, - }, - } - _, err := controllerutil.CreateOrUpdate(ctx, g.Client, deployment, func() error { - if err := controllerutil.SetControllerReference(resource, deployment, g.Scheme); err != nil { - log.Error(err, "Setting controller ref on git server deployment resource") - return err - } - - // Deployment selector is immutable so we set this value only if - // a new object is going to be created - if deployment.ObjectMeta.CreationTimestamp.IsZero() { - deployment.Spec.Selector = &metav1.LabelSelector{ - MatchLabels: GetGitServerLabels(resource), - } - } - - SetGitDeploymentPodTemplateSpec(resource, deployment) - return nil - }) - if err != nil { - return ctrl.Result{}, err - } - - resource.Status.DeploymentAvailable = deployment.Status.AvailableReplicas >= 1 - - if !resource.Status.DeploymentAvailable { - log.Info("Waiting for deployment to become available...") - return ctrl.Result{ - RequeueAfter: time.Second * 10, - }, nil - } - - return ctrl.Result{}, err -} - -func (g *GitServerReconciler) reconcileService(ctx context.Context, req ctrl.Request, resource *v1alpha1.GitServer) (ctrl.Result, error) { - log := log.FromContext(ctx) - - service := &v1.Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: managedResourceName(resource), - Namespace: resource.Namespace, - }, - } - _, err := controllerutil.CreateOrUpdate(ctx, g.Client, service, func() error { - if err := controllerutil.SetControllerReference(resource, service, g.Scheme); err != nil { - log.Error(err, "Setting controller ref on git server service resource") - return err - } - - SetServiceSpec(resource, service) - return nil - }) - if err != nil { - log.Error(err, "Create or update gitserver service", "resource", service) - } - return ctrl.Result{}, err -} - -func (g *GitServerReconciler) reconcileIngress(ctx context.Context, req ctrl.Request, resource *v1alpha1.GitServer) (ctrl.Result, error) { - log := log.FromContext(ctx) - - ingress := &networkingv1.Ingress{ - ObjectMeta: metav1.ObjectMeta{ - Name: managedResourceName(resource), - Namespace: resource.Namespace, - }, - } - - _, err := controllerutil.CreateOrUpdate(ctx, g.Client, ingress, func() error { - if err := controllerutil.SetControllerReference(resource, ingress, g.Scheme); err != nil { - log.Error(err, "Setting controller ref on git server ingress resource") - return err - } - - SetIngressSpec(resource, ingress) - return nil - }) - if err != nil { - log.Error(err, "Create or update gitserver service", "resource", ingress) - } - return ctrl.Result{}, err -} - -func (g *GitServerReconciler) ReconcileGitServer(ctx context.Context, req ctrl.Request, resource *v1alpha1.GitServer) (ctrl.Result, error) { - log := log.FromContext(ctx) - - // Validate source - if err := g.ValidateSource(resource); err != nil { - log.Error(err, "Invalid image source") - return ctrl.Result{}, err - } - - subReconcilers := []subReconciler{ - g.reconcileGitServerImage, - g.reconcileDeployment, - g.reconcileService, - g.reconcileIngress, - } - - for _, sub := range subReconcilers { - result, err := sub(ctx, req, resource) - if err != nil || result.Requeue || result.RequeueAfter != 0 { - return result, err - } - } - - return ctrl.Result{}, nil -} - -// Responsible to updating ObservedGeneration in status -func (g *GitServerReconciler) postProcessReconcile(ctx context.Context, req ctrl.Request, resource *v1alpha1.GitServer) { - log := log.FromContext(ctx) - - resource.Status.ObservedGeneration = resource.GetGeneration() - if err := g.Status().Update(ctx, resource); err != nil { - log.Error(err, "Failed to update resource status after reconcile") - } -} - -func (g *GitServerReconciler) ValidateSource(resource *v1alpha1.GitServer) error { - if resource.Spec.Source.Embedded && resource.Spec.Source.Image != "" { - return fmt.Errorf("cannot specify image with embedded set to true") - } - if !resource.Spec.Source.Embedded && resource.Spec.Source.Image == "" { - return fmt.Errorf("must specify embedded or image source") - } - return nil -} - -func (g *GitServerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - log := log.FromContext(ctx) - - var gitServer v1alpha1.GitServer - if err := g.Get(ctx, req.NamespacedName, &gitServer); err != nil { - log.Error(err, "unable to fetch Resource") - // we'll ignore not-found errors, since they can't be fixed by an immediate - // requeue (we'll need to wait for a new notification), and we can get them - // on deleted requests. - return ctrl.Result{}, client.IgnoreNotFound(err) - } - - // Make sure we post process - defer g.postProcessReconcile(ctx, req, &gitServer) - - return g.ReconcileGitServer(ctx, req, &gitServer) -} - -func (g *GitServerReconciler) SetupWithManager(mgr ctrl.Manager) error { - return ctrl.NewControllerManagedBy(mgr). - For(&v1alpha1.GitServer{}). - Owns(&appsv1.Deployment{}). - Complete(g) -} diff --git a/pkg/controllers/gitserver/controller_test.go b/pkg/controllers/gitserver/controller_test.go deleted file mode 100644 index 03acb290..00000000 --- a/pkg/controllers/gitserver/controller_test.go +++ /dev/null @@ -1,148 +0,0 @@ -package gitserver - -import ( - "context" - "fmt" - "path/filepath" - "runtime" - "testing" - "testing/fstest" - "time" - - "github.com/cnoe-io/idpbuilder/globals" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/selection" - "k8s.io/client-go/kubernetes" - - "github.com/cnoe-io/idpbuilder/api/v1alpha1" - "github.com/cnoe-io/idpbuilder/pkg/k8s" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/envtest" -) - -const ( - ResourceName = "test" - ResourceNamespace = "default" - - timeout = time.Second * 10 - interval = time.Millisecond * 250 -) - -func TestGitServerController(t *testing.T) { - //specify testEnv configuration - scheme := k8s.GetScheme() - testEnv := &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "resources")}, - ErrorIfCRDPathMissing: true, - Scheme: scheme, - BinaryAssetsDirectory: filepath.Join("..", "..", "..", "bin", "k8s", - fmt.Sprintf("1.27.1-%s-%s", runtime.GOOS, runtime.GOARCH)), - } - - //start testEnv - cfg, err := testEnv.Start() - if err != nil { - t.Fatalf("Starting testenv: %v", err) - } - defer testEnv.Stop() - - // Start controller - k8sManager, err := ctrl.NewManager(cfg, ctrl.Options{ - Scheme: scheme, - }) - k8sClient := k8sManager.GetClient() - if err != nil { - t.Fatalf("Creating controller manager: %v", err) - } - if err := (&GitServerReconciler{ - Client: k8sClient, - Scheme: k8sManager.GetScheme(), - Content: fstest.MapFS{ - "Dockerfile": &fstest.MapFile{ - Data: []byte("FROM nginx\n"), - Mode: 0666, - }, - }, - }).SetupWithManager(k8sManager); err != nil { - t.Fatalf("Unable to create controller with manager: %v", err) - } - - // Run manager in background - ctx, ctxCancel := context.WithCancel(context.Background()) - stoppedCh := make(chan error) - go func() { - err := k8sManager.Start(ctx) - t.Log("Controller stopped") - stoppedCh <- err - }() - - // Defer controller shutdown - defer func() { - ctxCancel() - err := <-stoppedCh - if err != nil { - t.Errorf("Starting controller manager: %v", err) - t.FailNow() - } - }() - - // Create GitServer resource - resource := &v1alpha1.GitServer{ - TypeMeta: v1.TypeMeta{ - APIVersion: v1alpha1.GroupVersion.Identifier(), - Kind: "GitServer", - }, - ObjectMeta: v1.ObjectMeta{ - Name: ResourceName, - Namespace: ResourceNamespace, - UID: "test-uid", - }, - Spec: v1alpha1.GitServerSpec{Source: v1alpha1.GitServerSource{Image: "fake", Embedded: false}}, - } - if err := k8sClient.Create(ctx, resource); err != nil { - t.Fatalf("Creating resource: %v", err) - } - - labelReq, err := labels.NewRequirement("app", selection.Equals, []string{fmt.Sprintf("%s-%s", globals.ProjectName, resource.Name)}) - if err != nil { - t.Fatalf("Failed constructing label selector requrirement: %v", err) - } - selector := labels.NewSelector() - selector.Add(*labelReq) - clientSet, err := kubernetes.NewForConfig(cfg) - if err != nil { - t.Fatalf("Failed creating deployment client: %v", err) - } - - // Wait for GitServer deployment object to be created. - endTime := time.Now().Add(timeout) - for { - if time.Now().After(endTime) { - t.Fatal("Timed out waiting for resource available") - } - - deployment, err := clientSet.AppsV1().Deployments(resource.Namespace).Get(ctx, managedResourceName(resource), v1.GetOptions{}) - if err != nil { - if !errors.IsNotFound(err) { - t.Fatalf("Failed getting deployment: %v", err) - } - t.Log("Waiting for deployment object...") - time.Sleep(interval) - continue - } - - for k, v := range GetGitServerLabels(resource) { - val, ok := deployment.Spec.Selector.MatchLabels[k] - if !ok { - t.Fatalf("Expected deployment labels selector key, %s, not found", k) - } - if val != v { - t.Fatalf("Expected deployment labels selector val not found: %s", v) - } - } - - break - } -} diff --git a/pkg/controllers/gitserver/image.go b/pkg/controllers/gitserver/image.go deleted file mode 100644 index 0ed34715..00000000 --- a/pkg/controllers/gitserver/image.go +++ /dev/null @@ -1,65 +0,0 @@ -package gitserver - -import ( - "context" - "fmt" - - "github.com/cnoe-io/idpbuilder/api/v1alpha1" - "github.com/cnoe-io/idpbuilder/globals" - "github.com/cnoe-io/idpbuilder/pkg/apps" - "github.com/cnoe-io/idpbuilder/pkg/docker" - "github.com/cnoe-io/idpbuilder/pkg/kind" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/log" -) - -func GetImageTag(resource *v1alpha1.GitServer) string { - return fmt.Sprintf("localhost:%d/%s-%s-%s-gitserver", kind.ExposedRegistryPort, globals.ProjectName, resource.Namespace, resource.Name) -} - -func GetImageUrl(resource *v1alpha1.GitServer) string { - if resource.Spec.Source.Embedded { - return fmt.Sprintf("%s@%s", GetImageTag(resource), resource.Status.ImageID) - } - return resource.Spec.Source.Image -} - -func (g *GitServerReconciler) reconcileGitServerImage(ctx context.Context, req ctrl.Request, resource *v1alpha1.GitServer) (ctrl.Result, error) { - log := log.FromContext(ctx) - - // If we're not using the embedded source, bail - if !resource.Spec.Source.Embedded { - log.Info("Not using embedded source, skipping image building") - return ctrl.Result{}, nil - } - - dockerClient, err := docker.GetDockerClient() - if err != nil { - return ctrl.Result{}, err - } - defer dockerClient.Close() - - imageTag := GetImageTag(resource) - - // Build image - _, err = apps.BuildAppsImage(ctx, dockerClient, []string{imageTag}, map[string]string{ - gitServerLabelKey: resource.GetName(), - }, g.Content) - if err != nil { - return ctrl.Result{}, err - } - - // Push image - regImgId, err := apps.PushImage(ctx, dockerClient, imageTag) - if err != nil { - return ctrl.Result{}, err - } - - if regImgId == nil { - return ctrl.Result{}, fmt.Errorf("failed to get registry image id after push") - } - - resource.Status.ImageID = *regImgId - - return ctrl.Result{}, nil -} diff --git a/pkg/controllers/gitserver/image_test.go b/pkg/controllers/gitserver/image_test.go deleted file mode 100644 index c36a1a99..00000000 --- a/pkg/controllers/gitserver/image_test.go +++ /dev/null @@ -1,121 +0,0 @@ -package gitserver - -import ( - "context" - "fmt" - "io" - "os" - "strings" - "testing" - "time" - - "github.com/cnoe-io/idpbuilder/api/v1alpha1" - "github.com/cnoe-io/idpbuilder/pkg/apps" - "github.com/cnoe-io/idpbuilder/pkg/docker" - "github.com/cnoe-io/idpbuilder/pkg/kind" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/filters" - "github.com/docker/go-connections/nat" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - controllerruntime "sigs.k8s.io/controller-runtime" - logf "sigs.k8s.io/controller-runtime/pkg/log" - "sigs.k8s.io/controller-runtime/pkg/log/zap" -) - -func TestReconcileGitServerImage(t *testing.T) { - logf.SetLogger(zap.New(zap.UseDevMode(true))) - - appsFS, err := apps.GetAppsFS() - if err != nil { - t.Fatalf("Getting apps FS: %v", err) - } - - ctx := context.Background() - r := GitServerReconciler{ - Content: appsFS, - } - resource := v1alpha1.GitServer{ - ObjectMeta: metav1.ObjectMeta{ - Name: "testcase", - }, - Spec: v1alpha1.GitServerSpec{ - Source: v1alpha1.GitServerSource{ - Embedded: true, - }, - }, - } - - dockerClient, err := docker.GetDockerClient() - if err != nil { - t.Errorf("Getting docker client: %v", err) - } - defer dockerClient.Close() - reader, err := dockerClient.ImagePull(ctx, "docker.io/library/registry:2", types.ImagePullOptions{}) - defer reader.Close() - // blocks until pull is completed - io.Copy(os.Stdout, reader) - if err != nil { - t.Fatalf("failed pulilng registry image: %v", err) - } - - resp, err := dockerClient.ContainerCreate(ctx, &container.Config{ - Image: "docker.io/library/registry:2", - Tty: false, - ExposedPorts: nat.PortSet{ - nat.Port(fmt.Sprintf("%d/tcp", kind.InternalRegistryPort)): struct{}{}, - }, - }, &container.HostConfig{ - PortBindings: nat.PortMap{ - nat.Port(fmt.Sprintf("%d/tcp", kind.InternalRegistryPort)): []nat.PortBinding{ - { - HostIP: "0.0.0.0", - HostPort: fmt.Sprintf("%d", kind.ExposedRegistryPort), - }, - }, - }, - }, nil, nil, "testcase-registry") - if err != nil { - t.Fatalf("failed creating registry container %v", err) - } - - defer dockerClient.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{Force: true}) - - waitTimeout := time.Second * 90 - waitInterval := time.Second * 3 - endTime := time.Now().Add(waitTimeout) - // avoid failures with the container that uses port 5001 in TestReconcileRegistry - for { - if time.Now().After(endTime) { - t.Fatalf("Timed out waiting for idpbuilder-testcase-registry container to terminate") - } - containers, _ := dockerClient.ContainerList(ctx, types.ContainerListOptions{ - Filters: filters.NewArgs(filters.KeyValuePair{ - Key: "name", - Value: "idpbuilder-testcase-registry", - }), - }) - if len(containers) == 0 { - break - } - time.Sleep(waitInterval) - } - err = dockerClient.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}) - if err != nil { - t.Fatalf("failed starting container %v", err) - } - - _, err = r.reconcileGitServerImage(ctx, controllerruntime.Request{}, &resource) - if err != nil { - t.Fatalf("reconcile error: %v", err) - } - - if !strings.HasPrefix(resource.Status.ImageID, "sha256") { - t.Fatalf("Invalid or no Image ID in status: %q", resource.Status.ImageID) - } - imageNameID := fmt.Sprintf("%s@%s", GetImageTag(&resource), resource.Status.ImageID) - _, err = dockerClient.ImageRemove(ctx, imageNameID, types.ImageRemoveOptions{}) - if err != nil { - t.Errorf("Removing docker image: %v", err) - } -} diff --git a/pkg/controllers/localbuild/controller.go b/pkg/controllers/localbuild/controller.go index 3fe20521..a303ad62 100644 --- a/pkg/controllers/localbuild/controller.go +++ b/pkg/controllers/localbuild/controller.go @@ -13,9 +13,7 @@ import ( argov1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" "github.com/cnoe-io/idpbuilder/api/v1alpha1" "github.com/cnoe-io/idpbuilder/globals" - "github.com/cnoe-io/idpbuilder/pkg/apps" "github.com/cnoe-io/idpbuilder/pkg/resources/localbuild" - "github.com/cnoe-io/idpbuilder/pkg/util" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -28,26 +26,9 @@ import ( ) const ( - defaultArgoCDProjectName string = "default" - EmbeddedGitServerName string = "embedded" - gitServerIngressHostnameBase string = ".cnoe.localtest.me" - repoUrlFmt string = "http://%s.%s.svc/idpbuilder-resources.git" + defaultArgoCDProjectName string = "default" ) -func getRepoUrl(resource *v1alpha1.GitServer) string { - return fmt.Sprintf(repoUrlFmt, managedResourceName(resource), resource.Namespace) -} - -var gitServerLabelKey string = fmt.Sprintf("%s-gitserver", globals.ProjectName) - -func ingressHostname(resource *v1alpha1.GitServer) string { - return fmt.Sprintf("%s%s", resource.Name, gitServerIngressHostnameBase) -} - -func managedResourceName(resource *v1alpha1.GitServer) string { - return fmt.Sprintf("%s-%s", globals.GitServerResourcename(), resource.Name) -} - type LocalbuildReconciler struct { client.Client Scheme *runtime.Scheme @@ -78,21 +59,8 @@ func (r *LocalbuildReconciler) Reconcile(ctx context.Context, req ctrl.Request) r.ReconcileProjectNamespace, r.ReconcileNginx, r.ReconcileArgo, - } - - switch localBuild.Spec.PackageConfigs.GitConfig.Type { - case globals.GitServerResourcename(): - subReconcilers = append( - subReconcilers, - []subReconciler{r.ReconcileEmbeddedGitServer, r.ReconcileArgoAppsWithGitServer}..., - ) - case globals.GiteaResourceName(): - subReconcilers = append( - subReconcilers, - []subReconciler{r.ReconcileGitea, r.ReconcileArgoAppsWithGitea}..., - ) - default: - return ctrl.Result{}, fmt.Errorf("GitConfig %s is invalid for LocalBuild %s", localBuild.Spec.PackageConfigs.GitConfig.Type, localBuild.GetName()) + r.ReconcileGitea, + r.ReconcileArgoAppsWithGitea, } for _, sub := range subReconcilers { @@ -144,140 +112,6 @@ func (r *LocalbuildReconciler) ReconcileProjectNamespace(ctx context.Context, re return ctrl.Result{}, err } -func (r *LocalbuildReconciler) ReconcileEmbeddedGitServer(ctx context.Context, req ctrl.Request, resource *v1alpha1.Localbuild) (ctrl.Result, error) { - log := log.FromContext(ctx) - - // Bail if argo is not yet available - if !resource.Status.ArgoCD.Available { - log.Info("argo not yet available, not installing embedded git server") - return ctrl.Result{}, nil - } - - // Bail if embedded argo applications not enabled - if !resource.Spec.PackageConfigs.EmbeddedArgoApplications.Enabled { - log.Info("embedded argo applications disabled, not installing embedded git server") - return ctrl.Result{}, nil - } - - gitServerResource := &v1alpha1.GitServer{ - ObjectMeta: metav1.ObjectMeta{ - Name: EmbeddedGitServerName, - Namespace: globals.GetProjectNamespace(resource.Name), - }, - } - - log.Info("Create or update git server", "resource", gitServerResource) - _, err := controllerutil.CreateOrUpdate(ctx, r.Client, gitServerResource, func() error { - if err := controllerutil.SetControllerReference(resource, gitServerResource, r.Scheme); err != nil { - log.Error(err, "Setting controller ref on git server resource") - return err - } - - gitServerResource.Spec.Source.Embedded = true - return nil - }) - if err != nil { - log.Error(err, "Create or Update git server resource") - } - - // Bail if the GitServer deployment is not yet available - if !gitServerResource.Status.DeploymentAvailable { - log.Info("Waiting for GitServer to become available before creating argo applications") - return ctrl.Result{ - RequeueAfter: time.Second * 10, - }, nil - } - - return ctrl.Result{}, err -} - -func (r *LocalbuildReconciler) ReconcileArgoAppsWithGitServer(ctx context.Context, req ctrl.Request, resource *v1alpha1.Localbuild) (ctrl.Result, error) { - log := log.FromContext(ctx) - - // Bail if embedded argo applications not enabled - if !resource.Spec.PackageConfigs.EmbeddedArgoApplications.Enabled { - log.Info("embedded argo applications disabled, not installing embedded git server") - r.shouldShutdown = true - return ctrl.Result{}, nil - } - - // Create argo project - // DeepEqual is broken on argo resources for some reason so we have to DIY create/update - project := &argov1alpha1.AppProject{ - ObjectMeta: metav1.ObjectMeta{ - Name: resource.GetArgoProjectName(), - Namespace: "argocd", - }, - } - if err := r.Client.Get(ctx, client.ObjectKeyFromObject(project), project); err != nil { - localbuild.SetProjectSpec(project) - log.Info("Creating project", "resource", project) - if err := r.Client.Create(ctx, project); err != nil { - log.Error(err, "Creating argo project", "resource", project) - return ctrl.Result{}, err - } - } - - foundGitServer := &v1alpha1.GitServer{ - ObjectMeta: metav1.ObjectMeta{ - Name: EmbeddedGitServerName, - Namespace: globals.GetProjectNamespace(resource.Name), - }, - } - - err := r.Client.Get(ctx, client.ObjectKeyFromObject(foundGitServer), foundGitServer) - if err != nil && errors.IsNotFound(err) { - log.Error(err, "Could not find GitServer") - return ctrl.Result{}, err - } - - if !foundGitServer.Spec.Source.Embedded { - log.Info("Not using embedded source, skipping argo app creation") - return ctrl.Result{}, nil - } - - // Install Argo Apps - for _, embedApp := range apps.EmbedApps { - log.Info("Ensuring Argo Application", "name", embedApp.Name) - app := &argov1alpha1.Application{ - ObjectMeta: metav1.ObjectMeta{ - Name: resource.GetArgoApplicationName(embedApp.Name), - Namespace: "argocd", - }, - } - - if err := controllerutil.SetControllerReference(resource, app, r.Scheme); err != nil { - return ctrl.Result{}, err - } - - if err := r.Client.Get(ctx, client.ObjectKeyFromObject(app), app); err != nil { - log.Info("Argo app doesnt exist, creating", "name", embedApp.Name) - repoUrl := getRepoUrl(foundGitServer) - - localbuild.SetApplicationSpec( - app, - repoUrl, - embedApp.Path, - defaultArgoCDProjectName, - "argocd", - nil, - ) - - if err := r.Client.Create(ctx, app); err != nil { - log.Error(err, "Creating argo app", "resource", app) - return ctrl.Result{}, err - } - } else { - log.Info("Argo app exists, skipping", "name", embedApp.Name) - } - } - - resource.Status.ArgoCD.AppsCreated = true - r.shouldShutdown = true - - return ctrl.Result{}, nil -} - // SetupWithManager sets up the controller with the Manager. func (r *LocalbuildReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). @@ -298,13 +132,6 @@ func (r *LocalbuildReconciler) ReconcileArgoAppsWithGitea(ctx context.Context, r return result, fmt.Errorf("reconciling bootstrap apps %w", err) } } - // do the same for embedded applications - for _, embedApp := range apps.EmbedApps { - result, err := r.reconcileEmbeddedApp(ctx, embedApp.Name, resource) - if err != nil { - return result, fmt.Errorf("reconciling embedded apps %w", err) - } - } if resource.Spec.PackageConfigs.CustomPackageDirs != nil { for i := range resource.Spec.PackageConfigs.CustomPackageDirs { result, err := r.reconcileCustomPkg(ctx, resource, resource.Spec.PackageConfigs.CustomPackageDirs[i]) @@ -520,8 +347,6 @@ func GetEmbeddedRawInstallResources(name string) ([][]byte, error) { switch name { case "argocd": return RawArgocdInstallResources() - case "backstage", "crossplane": - return util.ConvertFSToBytes(apps.EmbeddedAppsFS, fmt.Sprintf("srv/%s", name)) case "gitea": return RawGiteaInstallResources() case "nginx": diff --git a/pkg/controllers/resources/idpbuilder.cnoe.io_gitservers.yaml b/pkg/controllers/resources/idpbuilder.cnoe.io_gitservers.yaml deleted file mode 100644 index 0c39464a..00000000 --- a/pkg/controllers/resources/idpbuilder.cnoe.io_gitservers.yaml +++ /dev/null @@ -1,70 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.12.0 - name: gitservers.idpbuilder.cnoe.io -spec: - group: idpbuilder.cnoe.io - names: - kind: GitServer - listKind: GitServerList - plural: gitservers - singular: gitserver - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - properties: - source: - properties: - embedded: - description: Emedded enables the image containing the go binary - embedded contents - type: boolean - image: - description: Image specifies a docker image to use. Specifying - this disables installation of embedded applications. - type: string - type: object - type: object - status: - properties: - deploymentAvailable: - type: boolean - host: - description: Host is the host value of the ingress rule - type: string - imageID: - description: ImageID is the id of the most recently generated docker - image or empty if no image has been created - type: string - observedGeneration: - description: ObservedGeneration is the 'Generation' of the Service - that was last processed by the controller. - format: int64 - type: integer - required: - - deploymentAvailable - type: object - type: object - served: true - storage: true - subresources: - status: {} diff --git a/pkg/kind/cluster.go b/pkg/kind/cluster.go index 6e3960dd..8ce9dc42 100644 --- a/pkg/kind/cluster.go +++ b/pkg/kind/cluster.go @@ -73,17 +73,11 @@ func (c *Cluster) getConfig() ([]byte, error) { retBuff := bytes.Buffer{} if err = template.Execute(&retBuff, struct { - RegistryHostname string - ExposedRegistryPort uint16 - InternalRegistryPort uint16 - KubernetesVersion string - ExtraPortsMapping []PortMapping + KubernetesVersion string + ExtraPortsMapping []PortMapping }{ - RegistryHostname: c.getRegistryContainerName(), - ExposedRegistryPort: ExposedRegistryPort, - InternalRegistryPort: InternalRegistryPort, - KubernetesVersion: c.kubeVersion, - ExtraPortsMapping: portMappingPairs, + KubernetesVersion: c.kubeVersion, + ExtraPortsMapping: portMappingPairs, }); err != nil { return []byte{}, err } diff --git a/pkg/kind/cluster_test.go b/pkg/kind/cluster_test.go index 06d59217..eb1f8fcc 100644 --- a/pkg/kind/cluster_test.go +++ b/pkg/kind/cluster_test.go @@ -19,10 +19,6 @@ func TestGetConfig(t *testing.T) { expectConfig := `# Kind kubernetes release images https://github.com/kubernetes-sigs/kind/releases kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 -containerdConfigPatches: -- |- - [plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:5001"] - endpoint = ["http://idpbuilder-testcase-registry:5000"] nodes: - role: control-plane image: "kindest/node:v1.26.3" @@ -55,10 +51,6 @@ func TestExtraPortMappings(t *testing.T) { expectConfig := `# Kind kubernetes release images https://github.com/kubernetes-sigs/kind/releases kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 -containerdConfigPatches: -- |- - [plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:5001"] - endpoint = ["http://idpbuilder-testcase-registry:5000"] nodes: - role: control-plane image: "kindest/node:v1.26.3" diff --git a/pkg/kind/registry.go b/pkg/kind/registry.go deleted file mode 100644 index 7ce316be..00000000 --- a/pkg/kind/registry.go +++ /dev/null @@ -1,114 +0,0 @@ -package kind - -import ( - "context" - "fmt" - "io" - "os" - - "github.com/cnoe-io/idpbuilder/globals" - "github.com/cnoe-io/idpbuilder/pkg/docker" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/network" - "github.com/docker/docker/client" - "github.com/docker/go-connections/nat" - "sigs.k8s.io/controller-runtime/pkg/log" -) - -const registryImage string = "registry:2" -const ExposedRegistryPort uint16 = 5001 -const InternalRegistryPort uint16 = 5000 - -func (c *Cluster) getRegistryContainerName() string { - return fmt.Sprintf("%s-%s-registry", globals.ProjectName, c.name) -} - -func (c *Cluster) getRegistryContainer(ctx context.Context, dockerClient *client.Client) (*types.Container, error) { - return docker.GetOneContainer(ctx, dockerClient, types.ContainerListOptions{ - Filters: filters.NewArgs(filters.KeyValuePair{ - Key: "name", - Value: c.getRegistryContainerName(), - }), - }) -} - -func (c *Cluster) ReconcileRegistry(ctx context.Context) error { - log := log.FromContext(ctx) - - log.Info("Reconciling registry container") - - dockerCli, err := docker.GetDockerClient() - if err != nil { - return err - } - defer dockerCli.Close() - - log.Info("Pulling registry image") - reader, err := dockerCli.ImagePull(ctx, registryImage, types.ImagePullOptions{}) - if err != nil { - return err - } - defer reader.Close() - io.Copy(os.Stdout, reader) - log.Info("Done pulling registry image") - - regContainer, err := c.getRegistryContainer(ctx, dockerCli) - if err != nil { - return err - } - if regContainer == nil { - log.Info("Creating registry container") - resp, err := dockerCli.ContainerCreate(ctx, &container.Config{ - Image: registryImage, - Tty: false, - ExposedPorts: nat.PortSet{ - nat.Port(fmt.Sprintf("%d/tcp", InternalRegistryPort)): struct{}{}, - }, - }, &container.HostConfig{ - PortBindings: nat.PortMap{ - nat.Port(fmt.Sprintf("%d/tcp", InternalRegistryPort)): []nat.PortBinding{ - { - HostIP: "0.0.0.0", - HostPort: fmt.Sprintf("%d", ExposedRegistryPort), - }, - }, - }, - }, nil, nil, c.getRegistryContainerName()) - if err != nil { - log.Error(err, "Error creating registry container") - return err - } - - if err := dockerCli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil { - return err - } - regContainer, err = c.getRegistryContainer(ctx, dockerCli) - if err != nil { - return err - } - } else { - log.Info("Registry container found, skipping create") - } - - onKindNetwork := false - for network := range regContainer.NetworkSettings.Networks { - if network == "kind" { - onKindNetwork = true - } - } - - if !onKindNetwork { - log.Info("Putting the registry container on the kind network") - err = dockerCli.NetworkConnect(ctx, "kind", regContainer.ID, &network.EndpointSettings{}) - if err != nil { - return err - } - } else { - log.Info("Registry container on kind network, skipping connecting network") - } - - log.Info("Done reconciling registry container") - return nil -} diff --git a/pkg/kind/registry_test.go b/pkg/kind/registry_test.go deleted file mode 100644 index 1f0c4a5b..00000000 --- a/pkg/kind/registry_test.go +++ /dev/null @@ -1,70 +0,0 @@ -package kind - -import ( - "context" - "testing" - "time" - - "github.com/cnoe-io/idpbuilder/pkg/docker" - "github.com/docker/docker/api/types" - ctrl "sigs.k8s.io/controller-runtime" -) - -func TestReconcileRegistry(t *testing.T) { - ctrl.Log.WithName("test") - ctx := context.Background() - - dockerCli, err := docker.GetDockerClient() - if err != nil { - t.Fatalf("Error getting docker client: %v", err) - } - defer dockerCli.Close() - - kindNetwork, err := dockerCli.NetworkCreate(ctx, "kind", types.NetworkCreate{}) - if err != nil { - t.Fatalf("Failed creaking kind network: %v", err) - } - defer dockerCli.NetworkRemove(ctx, kindNetwork.ID) - - // Create cluster - cluster, err := NewCluster("testcase", "v1.26.3", "", "", "") - if err != nil { - t.Fatalf("Initializing cluster resource: %v", err) - } - - // Create registry - defer dockerCli.ContainerRemove(ctx, cluster.getRegistryContainerName(), types.ContainerRemoveOptions{Force: true}) - waitTimeout := time.Second * 90 - waitInterval := time.Second * 3 - endTime := time.Now().Add(waitTimeout) - - for { - if time.Now().After(endTime) { - t.Fatalf("Timed out waiting for registry. recent error: %v", err) - } - err = cluster.ReconcileRegistry(ctx) - if err == nil { - break - } - t.Logf("Failed to reconcile: %v", err) - dockerCli.ContainerRemove(ctx, cluster.getRegistryContainerName(), types.ContainerRemoveOptions{Force: true}) - time.Sleep(waitInterval) - } - - // Get resulting container - container, err := cluster.getRegistryContainer(ctx, dockerCli) - if err != nil { - t.Fatalf("Error getting registry container after reconcile: %v", err) - } - defer dockerCli.ImageRemove(ctx, container.ImageID, types.ImageRemoveOptions{}) - - if container == nil { - t.Fatal("Expected registry container after reconcile but got nil") - } - - // Run a second reconcile to validate idempotency - err = cluster.ReconcileRegistry(ctx) - if err != nil { - t.Fatalf("Error reconciling registry: %v", err) - } -} diff --git a/pkg/kind/resources/kind.yaml b/pkg/kind/resources/kind.yaml index 0868c109..599b1545 100644 --- a/pkg/kind/resources/kind.yaml +++ b/pkg/kind/resources/kind.yaml @@ -1,10 +1,6 @@ # Kind kubernetes release images https://github.com/kubernetes-sigs/kind/releases kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 -containerdConfigPatches: -- |- - [plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:{{ .ExposedRegistryPort }}"] - endpoint = ["http://{{ .RegistryHostname }}:{{ .InternalRegistryPort }}"] nodes: - role: control-plane image: "kindest/node:{{ .KubernetesVersion }}"