Skip to content

Commit

Permalink
Merge branch 'labring:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mlhiter authored Oct 31, 2024
2 parents 93192b4 + e6a2f8b commit f7458e3
Show file tree
Hide file tree
Showing 18 changed files with 447 additions and 82 deletions.
16 changes: 13 additions & 3 deletions controllers/devbox/internal/controller/devbox_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,19 @@ func (r *DevboxReconciler) syncPod(ctx context.Context, devbox *devboxv1alpha1.D
case 0:
logger.Info("create pod")
logger.Info("next commit history", "commit", nextCommitHistory)
return r.createPod(ctx, devbox, expectPod, nextCommitHistory)
err := r.createPod(ctx, devbox, expectPod, nextCommitHistory)
if err != nil && helper.IsExceededQuotaError(err) {
logger.Info("devbox is exceeded quota, change devbox state to Stopped")
r.Recorder.Eventf(devbox, corev1.EventTypeWarning, "Devbox is exceeded quota", "Devbox is exceeded quota")
devbox.Spec.State = devboxv1alpha1.DevboxStateStopped
_ = r.Update(ctx, devbox)
return nil
}
if err != nil {
logger.Error(err, "create pod failed")
return err
}
return nil
case 1:
pod := &podList.Items[0]
// check pod container size, if it is 0, it means the pod is not running, return an error
Expand Down Expand Up @@ -419,11 +431,9 @@ func (r *DevboxReconciler) getRuntime(ctx context.Context, devbox *devboxv1alpha

// create a new pod, add predicated status to nextCommitHistory
func (r *DevboxReconciler) createPod(ctx context.Context, devbox *devboxv1alpha1.Devbox, expectPod *corev1.Pod, nextCommitHistory *devboxv1alpha1.CommitHistory) error {
logger := log.FromContext(ctx)
nextCommitHistory.Status = devboxv1alpha1.CommitStatusPending
nextCommitHistory.PredicatedStatus = devboxv1alpha1.CommitStatusPending
if err := r.Create(ctx, expectPod); err != nil {
logger.Error(err, "create pod failed")
return err
}
devbox.Status.CommitHistory = append(devbox.Status.CommitHistory, nextCommitHistory)
Expand Down
5 changes: 5 additions & 0 deletions controllers/devbox/internal/controller/helper/devbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"log/slog"
"sort"
"strings"

"crypto/ed25519"
"crypto/rand"
Expand Down Expand Up @@ -397,6 +398,10 @@ func GenerateResourceRequirements(devbox *devboxv1alpha1.Devbox, requestEphemera
}
}

func IsExceededQuotaError(err error) bool {
return strings.Contains(err.Error(), "exceeded quota")
}

func calculateResourceRequest(limit corev1.ResourceList) corev1.ResourceList {
if limit == nil {
return nil
Expand Down
153 changes: 122 additions & 31 deletions docs/website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,32 @@ const config = {

themeConfig: { // @type {import('@docusaurus/preset-classic').ThemeConfig}
metadata: [{ name: 'title', content: 'Sealos by 环界云' }],
// announcementBar: {
// id: 'sealos_tip',
// content: `
// <div class="sealos-banner-box">
// <div>${isDomesticSite ? 'If you are an international user, please visit 👉' : '如果您是国内用户,请直接访问 👉 '}</div>
// <div class="sealos-banner-btn" onclick="window.open('${isDomesticSite ? 'https://sealos.io' : 'https://sealos.run'}', '_blank');">
// ${isDomesticSite ? 'International Site' : '国内官网'}
// </div>
// <svg
// onclick="handleBannerClose()"
// width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
// <g clip-path="url(#clip0_1145_366)">
// <path d="M12 22C6.477 22 2 17.523 2 12C2 6.477 6.477 2 12 2C17.523 2 22 6.477 22 12C22 17.523 17.523 22 12 22Z" fill="white" fill-opacity="0.16"/>
// <path d="M12 21.75C6.61507 21.75 2.25 17.3849 2.25 12C2.25 6.61507 6.61507 2.25 12 2.25C17.3849 2.25 21.75 6.61507 21.75 12C21.75 17.3849 17.3849 21.75 12 21.75Z" stroke="white" stroke-opacity="0.1" stroke-width="0.5"/>
// <path d="M9.17184 7.75696L11.9998 10.586L14.8278 7.75696L16.2428 9.17196L13.4138 12L16.2428 14.828L14.8278 16.243L11.9998 13.414L9.17184 16.243L7.75684 14.828L10.5858 12L7.75684 9.17196L9.17184 7.75696Z" fill="white"/>
// </g>
// <defs>
// <clipPath id="clip0_1145_366">
// <rect width="24" height="24" fill="white"/>
// </clipPath>
// </defs>
// </svg>
// </div>
// `,
// isCloseable: true,
// },
announcementBar: {
id: 'sealos_tip',
content: `
<div class="sealos-banner-box">
<div>${isDomesticSite ? 'If you are an international user, please visit 👉' : '如果您是国内用户,请直接访问 👉 '}</div>
<div class="sealos-banner-btn" onclick="window.open('${isDomesticSite ? 'https://sealos.io' : 'https://sealos.run'}', '_blank');">
${isDomesticSite ? 'International Site' : '国内官网'}
</div>
<svg
onclick="handleBannerClose()"
width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_1145_366)">
<path d="M12 22C6.477 22 2 17.523 2 12C2 6.477 6.477 2 12 2C17.523 2 22 6.477 22 12C22 17.523 17.523 22 12 22Z" fill="white" fill-opacity="0.16"/>
<path d="M12 21.75C6.61507 21.75 2.25 17.3849 2.25 12C2.25 6.61507 6.61507 2.25 12 2.25C17.3849 2.25 21.75 6.61507 21.75 12C21.75 17.3849 17.3849 21.75 12 21.75Z" stroke="white" stroke-opacity="0.1" stroke-width="0.5"/>
<path d="M9.17184 7.75696L11.9998 10.586L14.8278 7.75696L16.2428 9.17196L13.4138 12L16.2428 14.828L14.8278 16.243L11.9998 13.414L9.17184 16.243L7.75684 14.828L10.5858 12L7.75684 9.17196L9.17184 7.75696Z" fill="white"/>
</g>
<defs>
<clipPath id="clip0_1145_366">
<rect width="24" height="24" fill="white"/>
</clipPath>
</defs>
</svg>
</div>
`,
isCloseable: true,
},
algolia: {
// Algolia 提供的应用 ID
appId: "SLTSB7B9Y0",
Expand Down Expand Up @@ -251,11 +251,7 @@ const config = {
{
src: "/global.js",
async: true
},
...(isDomesticSite ? [{
src: 'https://hm.baidu.com/hm.js?d8e8ecf669c47dc2512d3f1417e761f9',
async: true,
}] : [])
}
],
headTags: [
{
Expand All @@ -279,6 +275,101 @@ const config = {
},
}
},
function gtmPlugin (context, options) {
return {
name: 'docusaurus-gtm-plugin',
injectHtmlTags () {
return {
headTags: [
{
tagName: 'script',
innerHTML: `
(function() {
const hostname = window.location.hostname;
if (hostname !== 'sealos.run') {
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-5953N4CP');
}
})();
`,
},
],
preBodyTags: [
{
tagName: 'script',
innerHTML: `
if (window.location.hostname !== 'sealos.run') {
document.write('<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5953N4CP" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>');
}
`,
},
]
}
},
}
},
function umamiPlugin (context, options) {
return {
name: 'docusaurus-umami-plugin',
injectHtmlTags () {
return {
headTags: [
{
tagName: 'script',
innerHTML: `
(function() {
const hostname = window.location.hostname;
if (hostname === 'sealos.run') {
const script1 = document.createElement('script');
script1.src = 'https://umami.cloud.sealos.io/oishii';
script1.setAttribute('data-website-id', 'e5a8009f-7cb6-4841-9522-d23b96216b7a');
script1.async = true;
document.head.appendChild(script1);
} else {
const script2 = document.createElement('script');
script2.src = 'https://umami.cloud.sealos.io/oishii';
script2.setAttribute('data-website-id', 'a1c29ace-b288-431a-a2eb-8617d1d5b5ed');
script2.async = true;
document.head.appendChild(script2);
}
})();
`,
},
],
}
},
}
},
function baiduPlugin (context, options) {
return {
name: 'docusaurus-baidu-plugin',
injectHtmlTags () {
return {
headTags: [
{
tagName: 'script',
innerHTML: `
(function() {
const hostname = window.location.hostname;
if (hostname === 'sealos.run') {
var _hmt = _hmt || [];
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?d8e8ecf669c47dc2512d3f1417e761f9";
hm.async = true;
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
}
})();
`,
},
],
}
},
}
}
]
}

Expand Down
33 changes: 0 additions & 33 deletions docs/website/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import '@site/src/css/animate.css';
import Layout from '@theme/Layout';
import React, { useEffect, useMemo } from 'react';
import { Helmet } from 'react-helmet';
import { PC_MIN_WIDTH } from '../constants/platform';
import useWindow from '../hooks/useWindow';
import Capability from './components/Capability';
Expand All @@ -20,26 +19,6 @@ const Home = () => {
const isPc = useMemo(() => screenWidth > PC_MIN_WIDTH, [screenWidth]);
const { i18n } = useDocusaurusContext();

useEffect(() => {
const loadUmamiScript = () => {
const hostname = window.location.hostname;
if (hostname === 'sealos.run') {
const script1 = document.createElement('script');
script1.src = 'https://umami.cloud.sealos.io/oishii';
script1.setAttribute('data-website-id', 'e5a8009f-7cb6-4841-9522-d23b96216b7a');
script1.async = true;
document.head.appendChild(script1);
} else {
const script2 = document.createElement('script');
script2.src = 'https://umami.cloud.sealos.io/oishii';
script2.setAttribute('data-website-id', 'a1c29ace-b288-431a-a2eb-8617d1d5b5ed');
script2.async = true;
document.head.appendChild(script2);
}
};
loadUmamiScript();
}, []);

useEffect(() => {
const urlParams = new URLSearchParams(window.location.search);
const params: Record<string, string> = {};
Expand Down Expand Up @@ -83,18 +62,6 @@ const Home = () => {
}
/>
</Head>
<Helmet>
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-786053845" />
<script async>
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'AW-786053845');
gtag('event', 'conversion', {'send_to': 'AW-786053845/LpbTCJ-8-coYENX16PYC'});
`}
</script>
</Helmet>
<Layout>
<div className="home">
{/* <SaleBanner /> */}
Expand Down
1 change: 1 addition & 0 deletions frontend/providers/costcenter/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const App = ({ Component, pageProps }: AppProps) => {
(async () => {
try {
const { data } = await request<any, ApiResp<initDataRes>>('/api/platform/getAppConfig');
state.setEnv('realNameRechargeLimit', !!data?.REALNAME_RECHARGE_LIMIT);
state.setEnv('invoiceEnabled', !!data?.INVOICE_ENABLED);
state.setEnv('transferEnabled', !!data?.TRANSFER_ENABLED);
state.setEnv('rechargeEnabled', !!data?.RECHARGE_ENABLED);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { makeAPIClientByHeader } from '@/service/backend/region';
import { jsonRes } from '@/service/backend/response';
import { checkSealosUserIsRealName } from '@/utils/tools';
import type { NextApiRequest, NextApiResponse } from 'next';

export default async function handler(req: NextApiRequest, resp: NextApiResponse) {
Expand Down Expand Up @@ -28,6 +29,14 @@ export default async function handler(req: NextApiRequest, resp: NextApiResponse
const client = await makeAPIClientByHeader(req, resp);
if (!client) return;

const isRealName = await checkSealosUserIsRealName(client);
if (!isRealName) {
return jsonRes(resp, {
code: 403,
message: 'recharge is not allowed for non-real-name user'
});
}

const response = await client.post('/account/v1alpha1/gift-code/use', body);
const responseData = await response.data;
if (response.status !== 200) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { generatePaymentCrd, PaymentForm } from '@/constants/payment';
import { authSession } from '@/service/backend/auth';
import { ApplyYaml, GetUserDefaultNameSpace } from '@/service/backend/kubernetes';
import { makeAPIClientByHeader } from '@/service/backend/region';
import { jsonRes } from '@/service/backend/response';
import { deFormatMoney } from '@/utils/format';
import { checkSealosUserIsRealName } from '@/utils/tools';
import crypto from 'crypto';
import type { NextApiRequest, NextApiResponse } from 'next';

Expand Down Expand Up @@ -38,6 +40,17 @@ export default async function handler(req: NextApiRequest, resp: NextApiResponse
return jsonRes(resp, { code: 401, message: 'user not found' });
}

const client = await makeAPIClientByHeader(req, resp);
if (!client) return;

const isRealName = await checkSealosUserIsRealName(client);
if (!isRealName) {
return jsonRes(resp, {
code: 403,
message: 'recharge is not allowed for non-real-name user'
});
}

// do payment
const paymentName = crypto.randomUUID();
const namespace = GetUserDefaultNameSpace(kubeUser.name);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { generatePaymentCrd, PaymentForm } from '@/constants/payment';
import { authSession } from '@/service/backend/auth';
import { ApplyYaml, GetUserDefaultNameSpace } from '@/service/backend/kubernetes';
import { makeAPIClientByHeader } from '@/service/backend/region';
import { jsonRes } from '@/service/backend/response';
import { checkSealosUserIsRealName } from '@/utils/tools';
import crypto from 'crypto';
import type { NextApiRequest, NextApiResponse } from 'next';

Expand All @@ -23,6 +25,17 @@ export default async function handler(req: NextApiRequest, resp: NextApiResponse
});
}

const client = await makeAPIClientByHeader(req, resp);
if (!client) return;

const isRealName = await checkSealosUserIsRealName(client);
if (!isRealName) {
return jsonRes(resp, {
code: 403,
message: 'recharge is not allowed for non-real-name user'
});
}

const k8s_username = kc.getUsers()[0].name;
// do payment
const paymentName = crypto.randomUUID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { jsonRes } from '@/service/backend/response';
import { AppConfigType, DefaultAppConfig } from '@/types/config';

export type Response = {
REALNAME_RECHARGE_LIMIT: boolean;
RECHARGE_ENABLED: boolean;
TRANSFER_ENABLED: boolean;
STRIPE_ENABLED: boolean;
Expand Down Expand Up @@ -45,6 +46,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
initAppConfig();
jsonRes<Response>(res, {
data: {
REALNAME_RECHARGE_LIMIT: global.AppConfig.costCenter.realNameRechargeLimit,
RECHARGE_ENABLED: global.AppConfig.costCenter.recharge.enabled,
TRANSFER_ENABLED: global.AppConfig.costCenter.transferEnabled,
STRIPE_ENABLED: global.AppConfig.costCenter.recharge.payMethods.stripe.enabled,
Expand Down
Loading

0 comments on commit f7458e3

Please sign in to comment.